<?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 ring buffer library?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50834/how-to-use-the-ring-buffer-library</link><description>Hi! 
 I&amp;#39;m trying to implement a traditional ring buffer with the nrf_ringbuf library. I&amp;#39;m using nRF52840 DK with SDK 15.3.0 and SES. 
 I&amp;#39;m going to receive strings of data from UART and I will have up to something like 100 strings of data. I want the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Aug 2019 08:38:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50834/how-to-use-the-ring-buffer-library" /><item><title>RE: How to use the ring buffer library?</title><link>https://devzone.nordicsemi.com/thread/203985?ContentTypeID=1</link><pubDate>Wed, 14 Aug 2019 08:38:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ed1651b-f9c3-4a1f-a0f7-b94900557b23</guid><dc:creator>Marius</dc:creator><description>&lt;p&gt;Thank you for this answer. It solved my problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the ring buffer library?</title><link>https://devzone.nordicsemi.com/thread/203759?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 08:38:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d21840c2-1cfa-49c3-ba2b-95a662a53035</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi Marius!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The ring buffer implementation in the SDK does not overwrite old data unless the buffer has been read, so for example&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t err_code;                                                
uint8_t data1_in[] = {1,2,3,4};                                     
uint8_t data2_in[] = {5,6,7,8};                                     
uint8_t data3_in[] = {9,10,11,12};                                  
uint8_t data1_out[4]; 
uint8_t data2_out[8]; 

size_t  len_in   = sizeof(data1_in);                                 
size_t  len1_out = sizeof(data1_out);                                
size_t  len2_out = sizeof(data2_out);                                

err_code = nrf_ringbuf_cpy_put(&amp;amp;m_ringbuf, data1_in, &amp;amp;len_in);       
err_code = nrf_ringbuf_cpy_put(&amp;amp;m_ringbuf, data2_in, &amp;amp;len_in);       
err_code = nrf_ringbuf_cpy_get(&amp;amp;m_ringbuf, data1_out, &amp;amp;len1_out);    
	
err_code = nrf_ringbuf_cpy_put(&amp;amp;m_ringbuf, data3_in, &amp;amp;len_in);       
err_code = nrf_ringbuf_cpy_get(&amp;amp;m_ringbuf, data2_out, &amp;amp;len2_out);    &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;will give you the output&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/case_5F00_ring_5F00_buffer_5F00_output.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;This can be further confirmed bu examining the implementation of the nrf_ringbuf_cpy_put function in the /components/libraries/nrf_ringbuf.c file. Here, the function calculates available space based in the stored read and write index (rd_idx, wr_idx).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I would suggest using the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_queue.html"&gt;queue library&lt;/a&gt; instead.&amp;nbsp;If you enable NRF_QUEUE_MODE_OVERFLOW, the queue, if full, will overwrite the oldest element.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Heidi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>