<?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>Async UART API: how to get partially filled buffer for immediate processing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108391/async-uart-api-how-to-get-partially-filled-buffer-for-immediate-processing</link><description>Hi, 
 I&amp;#39;m developing an application using ncs 2.5.0. I&amp;#39;m setting up a UART connection between a nRF9160 and a nRF52840 to shovel data between the two, based on the central_uart example. Initially I set the timeout value for uart_rx_enable to SYS_FOREVER_US</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 19 Feb 2024 14:06:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108391/async-uart-api-how-to-get-partially-filled-buffer-for-immediate-processing" /><item><title>RE: Async UART API: how to get partially filled buffer for immediate processing</title><link>https://devzone.nordicsemi.com/thread/469553?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2024 14:06:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f5a6a6d-0dd9-4148-8d78-61bab69deb89</guid><dc:creator>WoutWG</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;&lt;span&gt;J&amp;oslash;rgen for the feedback. I&amp;#39;ll use the timeout feature indeed to limit CPU activity as that&amp;#39;s the main benefit of using the Async API.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Async UART API: how to get partially filled buffer for immediate processing</title><link>https://devzone.nordicsemi.com/thread/469511?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2024 12:55:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9d23b3f-ec85-4aa0-9daa-5dd9ab3a5f44</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]I was under the impression that UART_RX_BUF_REQUEST would be called the moment data starts coming in. Due to the implementation in&amp;nbsp; the central_uart sample, I would expect that a new buffer is provided, which would allow to immediately release the buffer which contains only the first data transmission, hence providing immediate processing of any incoming data.[/quote]
&lt;p&gt;&amp;quot;&lt;span&gt;When receiving starts to current buffer&amp;quot; in this context means whenever the &lt;em&gt;receive operation&lt;/em&gt;&amp;nbsp;has started, not necessarily that actual data reception have started. The UARTE peripheral in nRF52 and nRF91 supports &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/uarte.html#concept_l5y_hcm_wr"&gt;double buffering&lt;/a&gt;, which means you can provide a new buffer pointer as soon as the RXSTARTED event has been generated. Together with HW shortcut between ENDRX event and STARTRX task, this could give minimal latency for buffer swapping to prevent data-loss from CPU needing to update the buffer pointer when the buffer have been filled.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]&lt;p&gt;I can get partial buffers by actually setting the rx timeout to a value matching the&amp;nbsp;rate of the messages being sent.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Am I misinterpreting the documentation, and is the only way to get partial buffers using async UART API by setting RX timeout which is lower than the time it takes to completely fill a buffer? Or should I actually get a partially filled buffer released every time data is received?&lt;/p&gt;[/quote]
&lt;p&gt;&lt;span&gt;If you want to process received data in smaller chunks, you need to reduce your buffer size, or use the timeout feature. The HW does not give any indication&amp;nbsp;of number of received bytes until after reception have been stopped, but there is a HW event,&amp;nbsp;&lt;a title="EVENTS_RXDRDY" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/uarte.html?cp=5_0_0_5_33_8_7#register.EVENTS_RXDRDY"&gt;EVENTS_RXDRDY&lt;/a&gt;, that can be used as an indication when data is actually received. This event are used by the driver to count number of received bytes using a TIMER instance when&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.2/kconfig/index.html#CONFIG_UART_0_NRF_HW_ASYNC"&gt;&lt;/a&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.2/kconfig/index.html#CONFIG_UART_0_NRF_HW_ASYNC"&gt;CONFIG_UART_x_NRF_HW_ASYNC&lt;/a&gt;&amp;nbsp;is set. This event will also start the timeout timer, which will be reset whenever a new byte is received, until the timeout is hit.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you do not want to use the timeout, you would need to set a 1-byte RX buffer for every transfer, which will cause excessive CPU activity to process all the interrupts.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>