<?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>won&amp;#39;t get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100149/won-t-get-rx-timeout-on-peripheral-and-central-uart-example</link><description>When I run UART peripheral and central communication example, the uart RX wait until received 20 or 40bytes, how can I setup the timeout then the RX doesn’t need to wait for full 20/40bytes?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 03 Jun 2023 14:44:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100149/won-t-get-rx-timeout-on-peripheral-and-central-uart-example" /><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/429104?ContentTypeID=1</link><pubDate>Sat, 03 Jun 2023 14:44:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:646ab73f-a6c1-4ccf-8bc5-cf16f4c52ca6</guid><dc:creator>steveqin</dc:creator><description>&lt;p&gt;Edvin,&lt;/p&gt;
&lt;p&gt;Thank you very much! this fixed the timeout issue.&lt;/p&gt;
&lt;p&gt;Thank you very much again,&lt;/p&gt;
&lt;p&gt;Steve&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/428754?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2023 13:20:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03892f02-8348-4c8c-8bc5-3253eed8269d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I see.&lt;/p&gt;
&lt;p&gt;Disclaimer: I tested this in NCS v2.4.0, which was released today, but I believe the sample is equivalent in v2.3.0, apart from that you need to consider that the timeout is in µs and not ms.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I see that one instance of uart_rx_enable() uses a hardcoded 50, instead of UART_WAIT_FOR_RX, so you may want to replace that.&lt;/p&gt;
&lt;p&gt;Then, in your UART_RX_DISABLED event in&amp;nbsp;uart_cb(), you will see:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	case UART_RX_RDY:
		LOG_DBG(&amp;quot;UART_RX_RDY&amp;quot;);
		buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
		buf-&amp;gt;len += evt-&amp;gt;data.rx.len;

		if (disable_req) {
			return;
		}

		 if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
		     (evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) {
			disable_req = true;
			uart_rx_disable(uart);
		 }

		break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So this event will trigger after UART_WAIT_FOR_RX has timed out, but it will only disable the uart using uart_rx_disable(), which again will trigger the transmission of the UART data over BLE. This will only happen if the last byte is &amp;#39;\r&amp;#39; or &amp;#39;\n&amp;#39;, regardless of whether the UART has timed out or not. So try to remove that check, and trigger uart_rx_disable(), and set disable_req=true regardless of the last bytes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alternatively, to check whether the interrupt occurs, you can change LOG_DBG() to LOG_INF(), and monitor the RTT log to see whether the callback is triggered.&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><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/428187?ContentTypeID=1</link><pubDate>Tue, 30 May 2023 13:37:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70d6b48c-255d-400c-a629-4478d1827600</guid><dc:creator>steveqin</dc:creator><description>&lt;p&gt;I just test it, the timeout still doesn&amp;#39;t work, could&amp;nbsp; you let me know your test result? I really want to fix this problem.&lt;/p&gt;
&lt;p&gt;thank you very much,&lt;/p&gt;
&lt;p&gt;Steve&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/428061?ContentTypeID=1</link><pubDate>Tue, 30 May 2023 07:27:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33280e00-40cf-44cc-b98a-e1b472ef9922</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Sorry. I forgot that this was part of the UART library in NCS/Zephyr (it was not in the &amp;quot;old&amp;quot; nRF5 SDK).&lt;/p&gt;
&lt;p&gt;Note that there is in fact a bug here. The input number (100 in your case), is given in microsecons, not millisecons. So try increasing it a bit.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This bug, where the sample uses ms and the SDK uses microseconds is reported, and will be fixed in a future release. It was introduced when Zephyr went from ms to µs, a couple of releases ago.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you wanted to test with 100ms, try using the value 100000, and see if it behaves like you would expect.&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><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/427828?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 13:46:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75972ab8-40ae-4461-8dfe-939ee591aa10</guid><dc:creator>steveqin</dc:creator><description>&lt;p&gt;is this a bug? Can Nordic fix it? if there is no timeout why does this protocol still have a timeout parameter?&amp;nbsp;&lt;/p&gt;
&lt;pre class="wp-block-code copy-the-code-target language-c"&gt;&lt;code class="language-c" lang="c"&gt;&lt;span class="token function"&gt;uart_rx_enable&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;uart &lt;span class="token punctuation"&gt;,&lt;/span&gt;rx_buf&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;span class="token keyword"&gt;sizeof&lt;/span&gt; rx_buf&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;span class="token number"&gt;100&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last parameter is the timeout, which in the context of the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;uart_rx_enable()&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function will determine how fast we get notified on incoming data that is less than the whole buffer size. It is called the inactivity period, which is measured after receiving at least a byte. Pick a value that fits your application&amp;rsquo;s requirements. You can also disable the timeout by passing&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;SYS_FOREVER_US&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: won't get RX Timeout on peripheral and central uart example</title><link>https://devzone.nordicsemi.com/thread/427824?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 13:32:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:797fc63d-8fe4-4e85-9b3e-cf165fa81909</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;There is no timeout by default in UART. The protocol just sends byte by byte. I recommend that you set up a timer that you can reset whenever you receive a byte. If the timer times out, you can consider the message complete.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I guess you knew, but another possibility is to use a special character at the end of all messages, such as linefeed (\n - 0x0A), and use this to trigger the message complete action.&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>