<?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>Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104938/fixed-length-uart-frame-detect-on-zephyr</link><description>Hello. 
 I&amp;#39;ve got problem with detect uart frame received from another device. This device send me frames which has fixed lenght (20B) and it always starts with 2B header (&amp;quot;**&amp;quot;). 
 I used UART implementation with one static buffer. 
 
 
 
 I tried to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Nov 2023 07:56:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104938/fixed-length-uart-frame-detect-on-zephyr" /><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/453426?ContentTypeID=1</link><pubDate>Wed, 01 Nov 2023 07:56:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aecea9d2-a247-4a1f-97bd-a8cd0486f71b</guid><dc:creator>P_WE</dc:creator><description>&lt;p&gt;Very usefull thread. I&amp;#39;ve got solution of my problem. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/453007?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 11:40:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9516216b-f900-4cd1-9afa-4e9d48dee279</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. The unofficial sample you have based this on is not optimal, in the sense that it does not use double buffering.&amp;nbsp; You should&amp;nbsp;use double buffering, and it also makes sense to use large buffers (to avoid having too swap buffers too often). The last posts in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/104641/nrf52dk-nrf52832-uart-asynchronous-receive"&gt;this thread&lt;/a&gt; describe this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/452877?ContentTypeID=1</link><pubDate>Sat, 28 Oct 2023 17:53:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dedd3a92-4e53-480d-870c-a30e64bb5d1e</guid><dc:creator>P_WE</dc:creator><description>&lt;p&gt;My mistake, of course it is 115200. I didn&amp;#39;t notice&amp;nbsp;issue when baudrate is slower. The problem is that last byte is in the buffer, but it is not read by:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;k_msgq_get(&amp;amp;uart_rx_msgq, &amp;amp;incoming_message, K_FOREVER);&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is read when next frame has come.&lt;/p&gt;
&lt;p&gt;Frame has 20B length, buffer is 16B long.&lt;/p&gt;
&lt;p&gt;Situation is explained on&amp;nbsp;screens.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:436px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/872x480/__key/communityserver-discussions-components-files/4/5140.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:800px;max-width:1040px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/2080x1600/__key/communityserver-discussions-components-files/4/8267.png" /&gt;&lt;/p&gt;
&lt;p&gt;UART0 is read in separate thread. There is also BLE scanner active in one time.&lt;/p&gt;
&lt;p&gt;Regads,&lt;/p&gt;
&lt;p&gt;P_WE&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/5140.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/452806?ContentTypeID=1</link><pubDate>Fri, 27 Oct 2023 13:54:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8aa0755-a2cf-4299-b80b-6fb3e4635299</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do you mean&amp;nbsp;11520&lt;strong&gt;0 &lt;/strong&gt;baud?&amp;nbsp;Is it so that you don&amp;#39;t see this issue with lower baud rates?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/452772?ContentTypeID=1</link><pubDate>Fri, 27 Oct 2023 11:43:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb75343c-222d-4f6b-b754-538877f86cbf</guid><dc:creator>P_WE</dc:creator><description>&lt;p&gt;I used this code:&amp;nbsp;&lt;a id="" href="https://github.com/too1/ncs-uart-async-count-rx"&gt;https://github.com/too1/ncs-uart-async-count-rx&lt;/a&gt;&amp;nbsp;which is linked in another subject. It&amp;#39;s OK, beacause I get data lenght and data in buffer but unfortunetelly it doesn&amp;#39;t work well with 11520 baud. It&amp;#39;s&amp;nbsp;often&amp;nbsp;lose one byte. I read data in seperate thread.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void thread_serial_central(void)
{
	uart0_init();
	LOG_INF(&amp;quot;UART0 started&amp;quot;);
	struct uart_msg_queue_item incoming_message;

	while(1)
	{
		// This function will not return until a new message is ready
		k_msgq_get(&amp;amp;uart_rx_msgq, &amp;amp;incoming_message, K_FOREVER);
		
		static uint8_t string_buffer[UART_BUF_SIZE + 1];
		memcpy(string_buffer, incoming_message.bytes, incoming_message.length);
		string_buffer[incoming_message.length] = 0;
		
		LOG_INF(&amp;quot;RX %i: %s\n&amp;quot;, incoming_message.length, string_buffer);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;P_WE&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fixed length uart frame detect on Zephyr</title><link>https://devzone.nordicsemi.com/thread/451697?ContentTypeID=1</link><pubDate>Mon, 23 Oct 2023 11:43:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:685409cf-8d48-4fa2-9743-0dc9633e7cb0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not entierly clear to me what you receive and what you expect to receive? Can you show some examples and explain in more detail?&lt;/p&gt;
&lt;p&gt;Generally though, if you are looking for a specific pattern, I would consider keeping a buffer where you store incoming data and search for the full &amp;quot;packet&amp;quot; there, so that it does not matter if you first receive a part of it, and subsequently the last part.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>