<?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>Using UART different methods</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91547/using-uart-different-methods</link><description>I&amp;#39;m using nRF Connect SDK with nRF52840dk and going through the UART samples and currently have both the P olling and Async methods working to some extent. But questions for each. 
 With Polling I&amp;#39;m able to read/write seeming indefinitely but messages</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Sep 2022 10:54:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91547/using-uart-different-methods" /><item><title>RE: Using UART different methods</title><link>https://devzone.nordicsemi.com/thread/385232?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 10:54:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03757325-342b-48ae-a144-86d03f9b9da4</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Good to hear that you found a good solution. The best of luck with your project &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&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: Using UART different methods</title><link>https://devzone.nordicsemi.com/thread/384690?ContentTypeID=1</link><pubDate>Tue, 06 Sep 2022 05:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2fa22c4-3e2c-4b88-bcf5-ed3c53edab95</guid><dc:creator>baconcheese13</dc:creator><description>&lt;p&gt;Thanks for the direction! I ended up using async RX with a message queue, very similar to the implementation in the echo_bot example which fit my needs perfectly&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// serial.c
void serial_cb(const struct device* dev, void* user_data)
{
    uint8_t c;
    while (uart_irq_rx_ready(uart1_dev)) {
        uart_fifo_read(uart1_dev, &amp;amp;c, 1);
        bool is_break = c == &amp;#39;\n&amp;#39; || c == &amp;#39;\r&amp;#39;;

        if (is_break &amp;amp;&amp;amp; rx_buf_pos &amp;gt; 0) {
            rx_buf[rx_buf_pos] = &amp;#39;\0&amp;#39;;
            k_msgq_put(&amp;amp;uart_msgq, &amp;amp;rx_buf, K_NO_WAIT);
            rx_buf_pos = 0;
        } else if (!is_break &amp;amp;&amp;amp; rx_buf_pos &amp;lt; (sizeof(rx_buf) - 1)) {
            rx_buf[rx_buf_pos++] = c;
        }
    }
}

// main.c
while (1) {
	// will be a full line received from the message queue
	while (k_msgq_get(&amp;amp;uart_msgq, &amp;amp;tx_buf, K_NO_WAIT) == 0) {
		print_uart(&amp;quot;Echo: &amp;quot;);
		print_uart(tx_buf); 
		print_uart(&amp;quot;\r\n&amp;quot;);
	}
	// will be a single character from user to send to modem
	while (uart_poll_in(uart0_dev, &amp;amp;c) == 0) { 
		printk(&amp;quot;%c&amp;quot;, c);
		uart_poll_out(uart1_dev, c);
	}

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using UART different methods</title><link>https://devzone.nordicsemi.com/thread/384517?ContentTypeID=1</link><pubDate>Mon, 05 Sep 2022 09:13:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f96c6e6d-6e7b-4f05-9773-e45290b8af34</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is possible to copy the received data into a message queue or buffer. You just need to keep in mind that the offset value is for the source buffer in the UART driver, not for your own buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is an unofficial sample available &lt;a href="https://github.com/too1/ncs-uart-async-count-rx"&gt;here&lt;/a&gt; showing how you can handle UART async with non dynamic memory management. In particular take a look at the handling of the RX callback &lt;a href="https://github.com/too1/ncs-uart-async-count-rx/blob/master/src/main.c#L73"&gt;here&lt;/a&gt;.&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>