<?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>Interrupt Driven UART with Ring buffers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89316/interrupt-driven-uart-with-ring-buffers</link><description>HI, I need UART communication as mentioned in title of this thread. Is there any example or application available ?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jun 2022 14:36:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89316/interrupt-driven-uart-with-ring-buffers" /><item><title>RE: Interrupt Driven UART with Ring buffers</title><link>https://devzone.nordicsemi.com/thread/374775?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 14:36:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b4770f9-e78e-4b22-b0e0-2b8650b3bf0c</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Gulzar,&lt;/p&gt;
&lt;p&gt;We found this sample:&lt;/p&gt;
&lt;p&gt;&lt;a style="background-color:rgba(255, 255, 255, 1);color:rgba(79, 82, 178, 1);font-family:-apple-system, BlinkMacSystemFont, &amp;#39;Segoe UI&amp;#39;, system-ui, &amp;#39;Apple Color Emoji&amp;#39;, &amp;#39;Segoe UI Emoji&amp;#39;, &amp;#39;Segoe UI Web&amp;#39;, sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;text-decoration:underline;text-indent:0;text-transform:none;white-space:normal;" title="https://devzone.nordicsemi.com/f/nordic-q-a/74600/uart-rx-interrupt-driven-does-not-receive-characters-properly-zephyr-os" href="https://devzone.nordicsemi.com/f/nordic-q-a/74600/uart-rx-interrupt-driven-does-not-receive-characters-properly-zephyr-os" rel="noopener noreferrer" target="_blank"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/74600/uart-rx-interrupt-driven-does-not-receive-characters-properly-zephyr-os&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Does it look anything like what you are looking for?&lt;/p&gt;
&lt;p&gt;(I have not yet looked at all the details of your previous reply.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interrupt Driven UART with Ring buffers</title><link>https://devzone.nordicsemi.com/thread/374369?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2022 14:24:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9701829a-45b6-4f83-bee7-8133fa8c7109</guid><dc:creator>mexco</dc:creator><description>&lt;p&gt;I used following ISR function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct device *bms_uart;
uint8_t bms_double_buffer[2][CONFIG_BMS_UART_BUF_SIZE];
uint8_t *bms_buf_ptr = bms_double_buffer[0];

struct bms_msg_queue_item {
	uint8_t bytes[CONFIG_BMS_UART_BUF_SIZE];
	uint8_t length;
};

struct bms_msg_queue_item bms_incoming_message;
// UART RX message queue
K_MSGQ_DEFINE(bms_rx_msgq, sizeof(struct bms_msg_queue_item), CONFIG_BMS_UART_RX_MSG_QUEUE_SIZE, 2);


void bms_uart_cb(const struct device *x, void *user_data)
{
    int data_length = 0;
    uint8_t rcv, addr=0;
    bool new_data = false;
    while (uart_irq_update(x) &amp;amp;&amp;amp; uart_irq_is_pending(x))
    {        
        if (uart_irq_rx_ready(x)) 
        {
            data_length += uart_fifo_read(x, bms_buf_ptr, CONFIG_BMS_UART_BUF_SIZE);
            new_data = true;            
        }
        else { 
                if(new_data){
                if(data_length == CONFIG_BMS_UART_BUF_SIZE)
                {  
                    buffer_sel = !buffer_sel;    

                    if(buffer_sel == true)
                    memcpy(bms_incoming_message.bytes, bms_double_buffer[0], data_length);
                    else
                    memcpy(bms_incoming_message.bytes, bms_double_buffer[1], data_length);

                    bms_incoming_message.length = data_length;
                    if(k_msgq_put(&amp;amp;bms_rx_msgq, &amp;amp;bms_incoming_message, K_NO_WAIT) != 0){
                        printk(&amp;quot;Error: Uart1 RX message queue full!\n&amp;quot;);				
                    }
                }
                printk(&amp;quot;RCVD: %d&amp;quot;,data_length);
                }
            }
            //int size = sizeof(bms_tx_buf);daly_cmd_array
            int size = CONFIG_BMS_UART_TX_BUF_SIZE;
            if(uart_irq_tx_ready(x))
            {
                //data_length = uart_fifo_fill(x,bms_tx_buf,size);
                data_length = uart_fifo_fill(x,daly_cmd_array,size);
                // if(data_length == size)printk(&amp;quot;Tx: %s&amp;quot;, bms_tx_buf); 
                if(data_length == size)
                {
                    printk(&amp;quot;Tx: %d \n&amp;quot;, data_length);
                    for(data_length=0;data_length&amp;lt;13;data_length++)
                    {
                        printk(&amp;quot;%x&amp;quot;, daly_cmd_array[data_length]);
                        if(data_length != 12)printk(&amp;quot;,&amp;quot;);else printk(&amp;quot;\n&amp;quot;);
                    }
                    uart_irq_tx_disable(x);
                }        
            }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this the issue is that, I sent 13 bytes from Serial Device, after receiving 8 bytes, isr_wrapper file is called, pointing to the problem a shown in image.&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/pastedimage1656339133625v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;I gone through the library function&amp;nbsp;uart_fifo_read(). After Stepping through the ISR code, I reached to the function shown in image below.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&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/pastedimage1656339266624v2.png" /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;In this function, size&amp;gt;0 is only used and nowhere (size) number of bytes is captured to be equal to. The following code line saves only one byte always rx_data[0], because every time at the start of function is num_rx = 0.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;rx_data[num_rx++] = (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)data-&amp;gt;rx_data;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;I practically verified that only one byte is saved at index of rx_data[0] in every iteration and after 8 characters receive goes to isr_wrapper.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;1. What is use of third parameter in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;uart_fifo_read(x,x,Buffer_size) when it has not been used in implementation ?&lt;/div&gt;
&lt;div&gt;2. What is the issue related to isr_wrapper ?&lt;/div&gt;
&lt;div&gt;3. Does UART generate interrupt after every byte or may it be configured to interrupt after collecting Buffer_size bytes ? If yes, where to set ? If no, then, why to specify in&amp;nbsp;uart_fifo_read() ?&lt;/div&gt;
&lt;/div&gt;
&lt;span&gt;&amp;nbsp;4. In the above ISR function, problem is in&amp;nbsp;RX portion only,&amp;nbsp;TX working well.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interrupt Driven UART with Ring buffers</title><link>https://devzone.nordicsemi.com/thread/374277?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2022 08:02:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b13d11e4-a8d8-4e48-9583-9bb6f79dfe4c</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Gulzar, sorry for the delay. I will check what is available and get back to you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>