<?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>Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80174/getting-uart-transmitted-data-length</link><description>Hello, 
 I&amp;#39;m using nRF v1.5.1 SDK. 
 
 If I have my RX buffer to be of size say 6, and I transmit 7 bytes then my code will detect a full RX Buffer and go to the endrx_isr() with the first 6 bytes. Eventually, the 7th byte will replace the first byte</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Oct 2021 09:09:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80174/getting-uart-transmitted-data-length" /><item><title>RE: Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/thread/332536?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2021 09:09:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:980d36ea-791d-4593-9788-d0b1a5d2216a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Spencer&lt;/p&gt;
[quote user="SpencerEtn"]If i send a frame of data of [1,2,3,4,5,6,7] after the buffer would then become [7,2,3,4,5,6].[/quote]
&lt;p&gt;You mean the next one would be [7,1,2,3,4,5] right?&lt;/p&gt;
&lt;p&gt;Otherwise it looks like you have lost a byte, which would definitely be a problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you know how much of a delay there would be between each transaction?&lt;/p&gt;
&lt;p&gt;If the delay is relatively large you could always set a shorter timeout, so that the UART RX times out between each message.&amp;nbsp;&lt;br /&gt;This doesn&amp;#39;t make the buffers align like you request, but it would ensure that receive a complete message before the next one starts.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Message one would be received as: [1,2,3,4,5,6] followed by [7]&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then the second message would be [1,2,3,4,5] (with offset 1) followed by [6,7]&lt;/p&gt;
&lt;p&gt;Third message [1,2,3,4] (offset 2) followed by [5,6,7]&lt;/p&gt;
&lt;p&gt;And so on...&lt;/p&gt;
[quote user="SpencerEtn"]It may be more headache than it is worth but thanks for the help anyways![/quote]
&lt;p&gt;I think so, yes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is also risky to trust too much in the exact behavior of the UART driver, as this might change between SDK versions, or depending on which chip you are using.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/thread/332383?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 13:48:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3519b714-66c5-48ca-b8af-0d8892ba73e6</guid><dc:creator>SpencerEtn</dc:creator><description>&lt;p&gt;For instance, if I send [1,2,3,4,5,6,7] and the buffer is [1,2,3,4,5,6] after I send another the first frame. If i send a frame of data of [1,2,3,4,5,6,7] after the buffer would then become [7,2,3,4,5,6].&lt;/p&gt;
&lt;p&gt;We do have a header byte to mark the beginning of a new message but this would have just been an extra form of validation. It may be more headache than it is worth but thanks for the help anyways!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/thread/332252?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 08:11:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1dade7de-0056-466b-8033-61d52a1be067</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Spencer&lt;/p&gt;
&lt;p&gt;What do you mean by putting them in the wrong locations?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are the bytes printed in the while loop not the same as the bytes that you expect to receive?&lt;/p&gt;
&lt;p&gt;The incoming bytes will be placed at different offsets in the UART RX buffers, that is true, but you can compile them as you wish once you receive them.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you are implementing some form of message based UART communication I would strongly recommend using&amp;nbsp;a header byte or similar to mark the start of a new message.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/thread/332197?ContentTypeID=1</link><pubDate>Fri, 01 Oct 2021 18:00:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c12c4b04-62d5-4522-816a-d3e651d82ddd</guid><dc:creator>SpencerEtn</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Following your example it does seem to work the first time I try to send more than the buffer size. However, the next time I send 7 bytes again it would start putting them in wrong locations. Is there a way i&amp;#39;d be able to count the evt-&amp;gt;data rx/tx buf length before it gets manipulated in the callbacks? I think it&amp;#39;d be easier overall if I could just detect if say 7 bytes were received and to ignore them all and wait for a new set of bytes.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Spencer&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting UART transmitted data length</title><link>https://devzone.nordicsemi.com/thread/332110?ContentTypeID=1</link><pubDate>Fri, 01 Oct 2021 10:45:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bef8f88-814a-46bf-860c-fe7ece414212</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Spencer&lt;/p&gt;
&lt;p&gt;Have you looked into using the UART async driver?&lt;/p&gt;
&lt;p&gt;Then you can define a timeout on the receiver, and get a callback from the driver as soon as either one or the buffers have filled up, or the timeout period has passed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I made a small example showing how to implement this &lt;a href="https://github.com/too1/ncs-uart-async-count-rx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In your case this should lead to a first interrupt with a length of 6 bytes, followed by another interrupt some time later with the length of 1 containing the last byte.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>