<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103575/nrf52840-uart-send-more-than-256-bytes</link><description>I&amp;#39;m sending some data from nRF52840 to another device through wired UART. When data is less than 256-byte long, it works fine. But when it&amp;#39;s larger than 256 bytes, I get ERROR 4 [NRF_ERROR_NO_MEM]. I have already changed UART_TX_BUF_SIZE to 1024 in APP_UART_FIFO_INIT</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Sep 2023 17:20:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103575/nrf52840-uart-send-more-than-256-bytes" /><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/446350?ContentTypeID=1</link><pubDate>Fri, 15 Sep 2023 17:20:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bec3890-d11f-4f93-9421-cb6948bcfbe6</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;This solved the issue, thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/446029?ContentTypeID=1</link><pubDate>Thu, 14 Sep 2023 10:34:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9b03744-f383-4e88-95b5-5c0a12d70fee</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I see the problem now. In your&amp;nbsp;uart_send() implementation you have a for loop that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint16_t length = 257;
// loops forever when length &amp;gt; 255
for(uint8_t i=0; i&amp;lt;length; i++) 
{ 
    // send data
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;where the loop control variable &amp;#39;i&amp;#39; is an uint8_t which will overflow after reaching &amp;#39;256&amp;#39;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445908?ContentTypeID=1</link><pubDate>Wed, 13 Sep 2023 16:25:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f148c05-764a-4075-8e33-94d2ce2122b6</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;This is before scanning and anything else using UART.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445732?ContentTypeID=1</link><pubDate>Wed, 13 Sep 2023 06:05:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6cf5078-19d1-4811-8b24-809515d671b5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Why don&amp;#39;t you&amp;nbsp;try to send the data right after &amp;quot;uart_init&amp;quot; as shown in my code snippet before you start scanning, etc.? I&amp;#39;ve not been able to reproduce the error here with the NUS example.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445710?ContentTypeID=1</link><pubDate>Tue, 12 Sep 2023 22:59:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82e20935-94d2-4c3e-88e9-149b6bcf7df9</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;I added the following code to main before the loop&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t data_to_send[270];
	memset(&amp;amp;data_to_send[0], 0x41, sizeof(data_to_send));
	uint16_t data_length = 256;
	uart_send(00,data_length,data_to_send);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It works fine when data_length is 255.&lt;/p&gt;
&lt;p&gt;Getting&amp;nbsp;&lt;span&gt;NRF_ERROR_NO_MEM&amp;nbsp;when data_length is 256.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:640px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1280x480/__key/communityserver-discussions-components-files/4/Screenshot-2023_2D00_09_2D00_12-174426.png" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445585?ContentTypeID=1</link><pubDate>Tue, 12 Sep 2023 10:11:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3bed520-573f-4135-a6bd-e8bc306b4d9c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;It might be a good idea to check if you can send more than 257 bytes at the beginning of the main function before you begin scanning for BT devices.&lt;/p&gt;
&lt;p&gt;E.g.,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
    bool erase_bonds;
    
    // Initialize.
    uart_init();

    uint32_t data_len = 512; 
    uint8_t dummy_byte = &amp;#39;A&amp;#39;;

    for (int i=0; i &amp;lt; data_len; i++)
    {
        uint32_t err_code = app_uart_put(dummy_byte);
        APP_ERROR_CHECK(err_code);
    }
    ...&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445468?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 17:19:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75e521f2-af4b-4560-8631-24f04d203dad</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;I&amp;nbsp;send scan results through UART, so a lot up to this point. This function is only called once a peripheral is connected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I really doubt it has anything to do with potential data left in the buffer, because 255 is guaranteed to work, 257 is guaranteed to have error no matter how&amp;nbsp;long I have been scanning and sending scan results.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445467?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 17:15:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59e0fc9c-340d-481c-8e22-26278d0186f8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;How much data has been sent up to that point, and how often is this function being called? Your 1024-byte FIFO obviously shouldn&amp;#39;t return NRF_ERROR_NO_MEM if you&amp;#39;re only sending a single 257-byte packet.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445465?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 17:03:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08e0c39a-097e-4e78-b753-2dbf905b0c6e</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;This happens at line 753. This is the only place calling&amp;nbsp;uart_send function at that time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Data is set from line 719 to 722. Total array length is 270, I just play with&amp;nbsp;uint16_t data_length = 16. When data_length is set to 16, the total data to send is 257 and it reports error. If I change&amp;nbsp;&lt;span&gt;data_length to 14, total data length is 255 and it works.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445463?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 16:57:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c40fad5d-41e2-48b5-98a2-3ba5bae4d321</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, I can access the ticket. Are you&amp;nbsp;logging the UART output from the device when the error arises? I see that you&amp;nbsp;are sending UART data from multiple places in your code and it would be helpful to know how much data has been sent before the error occurs. The issue is likely that data is being added to the FIFO buffer faster than it&amp;#39;s being transmitted&amp;nbsp;over UART.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, where did you increase the packet length to 257 bytes?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445456?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 16:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c73970a1-0fdf-4540-9e2c-c5eb9fbc34c2</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;Just tried changing 1024 to 2048, it&amp;#39;s still the same error.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you have access to private case&amp;nbsp;314336? I posted the complete code there to ask for another question.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445453?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 15:44:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3def60ce-fa78-41f2-8867-7e671063d0a4</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;What I meant to suggest was that you increase the TX buffer size even further, e.g., from 1024 to 2048 bytes. This is to help narrow down the problem.&lt;/p&gt;
[quote userid="25706" url="~/f/nordic-q-a/103575/nrf52840-uart-send-more-than-256-bytes/445450"]The issue is guaranteed to happen when the data size is 257 bytes, but fine when the data size is 255 bytes. I assume&amp;nbsp;the difference of 2 bytes won&amp;#39;t have such huge impact?[/quote]
&lt;p&gt;Are you sending just one packet of 257 bytes when the error occurs? Can you post the relevant code here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445450?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 15:23:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d857e08f-4ae3-48ed-91c7-a6d6d1180bee</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;I have already increased TX buf size to 1024, hence I have this question.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The issue is guaranteed to happen when the data size is 257 bytes, but fine when the data size is 255 bytes. I assume&amp;nbsp;the difference of 2 bytes won&amp;#39;t have such huge impact?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445356?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 09:55:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:446b52b6-e0b9-4fd5-8fc4-d4bfb354b025</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;When you initiate a debug session in your IDE, you can set a breakpoint at the app_uart_put() call and then single-step into the function. However, after examining the app_uart_put() implementation, I found that only the app_fifo_put() function can return NRF_ERROR_NO_MEM. This&amp;nbsp;means&amp;nbsp;the FIFO&amp;nbsp;must be filling up faster than it&amp;#39;s being emptied.&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I suggest you try to increase the TX buf size further to see if it helps. You may also consider using the&amp;nbsp;&lt;a title="UART" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/hardware_driver_uart.html?cp=9_1_2_0_19"&gt;UART&lt;/a&gt;&amp;nbsp;driver or the&amp;nbsp;&lt;a title="Libuarte - advanced UARTE driver" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_libuarte.html?cp=9_1_3_28"&gt;Libuarte - advanced UARTE driver&lt;/a&gt;&amp;nbsp;to allow you to work with larger DMA buffers (app_uart only allows sending of 1-byte at a time).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445190?ContentTypeID=1</link><pubDate>Fri, 08 Sep 2023 15:48:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:beb851bd-b69f-41fc-b8b9-a44a2fc7994d</guid><dc:creator>xhr0428</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The printout from RTT viewer just shows&amp;nbsp;&lt;span&gt;NRF_ERROR_NO_MEM at the line of&amp;nbsp;app_uart_put(). How do I get deep into&amp;nbsp;app_uart_put()?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART send more than 256 bytes</title><link>https://devzone.nordicsemi.com/thread/445124?ContentTypeID=1</link><pubDate>Fri, 08 Sep 2023 11:31:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:453e7d86-c1de-44f9-a1ea-5b650cce598e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It should be sufficient to only increase the FIFO TX buffer. Are you able to debug the app to see exactly where the NRF_ERROR_NO_MEM is returned? Is it from the app_fifo_put() call in app_uart_put()?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>