<?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>How to use the RXTO</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93480/how-to-use-the-rxto</link><description>Hello, 
 
 I have an application that I receive data over the UART. The data being received can be of different lengths e.g. 12 bytes up to a maximum of 256 bytes. I want to know when the data coming in has stopped, so I know when to read the buffer.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Nov 2022 12:07:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93480/how-to-use-the-rxto" /><item><title>RE: How to use the RXTO</title><link>https://devzone.nordicsemi.com/thread/393849?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 12:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:036acfed-b2d2-49ee-871a-45b00171f432</guid><dc:creator>Edvin</dc:creator><description>[quote user="jerome.sc"]What if a PC was sending data over the UART to the nRF microcontroller, with the same conditions, i.e. random amount of bytes. Would the RXTO be used in this case?[/quote]
&lt;p&gt;No. You can read about the RXTO event here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/uarte.html?cp=4_1_0_5_31_2#concept_uzb_p2m_wr"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52833/uarte.html?cp=4_1_0_5_31_2#concept_uzb_p2m_wr&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The RXTO event will only occur after you have aborted the RX (which the driver usually handlers). It can not be used as a generic timeout.&lt;/p&gt;
&lt;p&gt;If you are sending data from a PC to the nRF over UART, you can probably add e.g. a &amp;#39;\n&amp;#39; (newline) character at the end of all &amp;quot;complete messages&amp;quot;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the RXTO</title><link>https://devzone.nordicsemi.com/thread/393730?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 15:28:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:376fd1a4-c6da-444b-b4de-b1d174b3be51</guid><dc:creator>jerome.sc</dc:creator><description>&lt;p&gt;Interesting, I&amp;#39;ll look into this way of implementing things.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What if a PC was sending data over the UART to the nRF microcontroller, with the same conditions, i.e. random amount of bytes. Would the RXTO be used in this case? To detect when the RX registers has stopped receiving data?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the RXTO</title><link>https://devzone.nordicsemi.com/thread/393697?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 14:27:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e30608a0-0408-4de0-b96d-ba3d5c87206c</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The RXTO is not what you are looking for in this case.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The UART protocol doesn&amp;#39;t have any means of telling the connected device how many bytes that are in a message. The same goes for the UART peripheral. It will only be notified every time one byte is received.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But your question is fairly common, because you would typically want to do something when you have received N bytes, but N is not necessarily constant, like in your case where you say that N can be 12 in one message, and 256 in the next.&lt;/p&gt;
&lt;p&gt;So to make this work there are two approaches.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1: This is by far the easiest one. If you look into the ble_app_uart example, you will see this implementation. Please note that the application itself will receive an interrupt on every byte, but the application logic is used to trigger only in certain events. Either if the buffer is full, or if the last received byte is \n (newline) (or any other special character that you decide). So in this case you would want to make your buffer large enough, so that you will only trigger on the special character that you are looking for.&lt;/p&gt;
&lt;p&gt;2: This is a bit more complex. It uses a timer to detect when the last received UART byte was received. If X time passes (x can be 1 second, 5 ms, or whatever you set). If the timer times out before you receive a new byte, it will assume that the &amp;quot;message&amp;quot; is done, and turn off the timer until a new byte is received.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you have some sort of special character that is present at the end of your incoming UART messages, I suggest that you use this. If you control the application on the transmitting side, consider adding it there if possible. If not, you will need to look into the timing approach. In that case, you can check out the SDK\examples\peripheral\libuarte example.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>