<?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>UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57552/uarte-clear-rx-buffer</link><description>Hello, there, 
 
 I am trying to get the UARTE working on a custom nRF52840 board. In my setup, I am expecting a response to every transmission on UART. 
 
 Here&amp;#39;s my setup code: 
 
 
 Here&amp;#39;s my event handler: 
 
 
 Here&amp;#39;s my application code: 
 
 
 While</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Feb 2020 17:30:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57552/uarte-clear-rx-buffer" /><item><title>RE: UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/thread/233606?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 17:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0484f124-0625-431a-88e0-0949863431d6</guid><dc:creator>tejaChintalapati</dc:creator><description>&lt;p&gt;Thank you Kenneth for the information.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I finally got the code working the way I want. Here&amp;#39;s the basic implementation that I will work on further:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Function: coreApplication
 * Params: None
 * returns: None
 * Description: Core Application Code
 */

void coreApplication(void) {
  char requestVersion[20] = {0x55, 0xA7, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x03, 0x01, 0x00, 0x00};

  UARTE0TransmitData(requestVersion, 16);

  uint8_t receivedData[30] = {0xFF};
  size_t lastPopSize = 0;

  while (1) {
    //If a queue is not empty, read the content and process the data.
    if (nrf_queue_is_empty(&amp;amp;UARTE0RxBufferQueue) == false) {

      UARTERxBufferStruct popBuffer;

      //Pop the data from the queue.
      nrf_queue_pop(&amp;amp;UARTE0RxBufferQueue, &amp;amp;popBuffer);
      
      //Copy the data into the buffer and process it.
      memcpy(&amp;amp;receivedData[lastPopSize], popBuffer.data, popBuffer.length);

      //Update this variable.
      lastPopSize = popBuffer.length;
    } else {
      //Reset the queue
      nrf_queue_reset(&amp;amp;UARTE0RxBufferQueue);

      //Reset the index
      lastPopSize = 0;

      //Reset the buffer
      memset(receivedData, 0xFF, sizeof(receivedData));

      //Toggle LED
      bsp_board_led_invert(0);
      
      //Transmit the heartbeat packet.
      UARTE0TransmitData(requestVersion, 16);
      nrf_delay_ms(500);
    }

    NRF_LOG_FLUSH();
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I appreciate the help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/thread/233567?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 14:42:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7585fc63-cb66-45d2-9fa5-c2bcb95f2649</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You are right that&amp;nbsp;&lt;em&gt;NRF_LIBUARTE_ASYNC_EVT_RX_DATA&lt;/em&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;comes on timeout and on buffer getting full, in your case the 9th message will be split on &lt;strong&gt;two&amp;nbsp;&lt;/strong&gt;&lt;em&gt;NRF_LIBUARTE_ASYNC_EVT_RX_DATA&lt;/em&gt;&amp;nbsp;events (instead of only one). I am not aware of any way to avoid that no. The risk of manipulation the buffers is that you may lose bytes.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/thread/233509?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 12:31:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c96b008d-cfbe-4c44-aa8a-15d9347941db</guid><dc:creator>tejaChintalapati</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/kenneth"&gt;Kenneth&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your response. I&amp;#39;m sorry that I didn&amp;#39;t ask my question correctly. Here&amp;#39;s what&amp;#39;s happening:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I initialised 3 buffers, each of 255 bytes wide.&lt;/li&gt;
&lt;li&gt;I sent some message to another system, which in-turn sends a 28 byte response.&lt;/li&gt;
&lt;li&gt;Everything works as expected. I get an event after 28 bytes until 9 times(252 bytes till now).&lt;/li&gt;
&lt;li&gt;After the 9th time, I again get an evert, as expected, because one buffer is filled. And then the buffer fills from start.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;What I want is this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;After I process a response from the other device, I want to reset the write location of Rx buffer so that it starts from beginning.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Can you please tell me how to achieve this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/thread/233495?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 12:04:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d42ca0c-f6c9-4f35-8cf2-4b444878c188</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;The libuarte provide lossless asynchronous transfer. If you have specific requirements to how to flushing buffers (I assume you have control of when you can do this safely in case it is in the middle of a tx/rx transfer) you will either need to modify the library or use a different uart example as a starting point.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I do not quite understand how you can overflow the libuarte, you can provide several buffers, and as long as you can handle incomming data before all buffers are all full you should be safe.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UARTE Clear Rx Buffer</title><link>https://devzone.nordicsemi.com/thread/233485?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 10:58:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae6aaf94-bba8-481b-bf41-2f0800822fb1</guid><dc:creator>tejaChintalapati</dc:creator><description>&lt;p&gt;Here&amp;#39;s some more information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I read all the answers in the forum before posting this question. I do understand that I can use app_uart_flush(). But, it clears &lt;strong&gt;BOTH&lt;/strong&gt; the buffers, which I don&amp;#39;t want because&amp;nbsp;I may be transmitting asynchronously.&lt;/li&gt;
&lt;li&gt;I referred to the timing diagram for &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fuarte.html"&gt;UARTE reception&lt;/a&gt;. However, it doesn&amp;#39;t show how to&amp;nbsp;reset the Rx buffer.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>