<?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>Serial timeout issues with nrf_serial_read() and nrf_serial_write() with nrf_serial_mode_irq.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57150/serial-timeout-issues-with-nrf_serial_read-and-nrf_serial_write-with-nrf_serial_mode_irq</link><description>Hi all, I&amp;#39;m facing an issue communicating with a UART-based sensor on the NRF52DK (52832). I&amp;#39;ve followed the serial_port example and using various forum topics I&amp;#39;ve got to the point where I can exchange and read data from the sensor using the serial_port</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jan 2020 15:45:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57150/serial-timeout-issues-with-nrf_serial_read-and-nrf_serial_write-with-nrf_serial_mode_irq" /><item><title>RE: Serial timeout issues with nrf_serial_read() and nrf_serial_write() with nrf_serial_mode_irq.</title><link>https://devzone.nordicsemi.com/thread/231735?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 15:45:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6730640a-97f5-4040-9337-a7708a58aca4</guid><dc:creator>nikostpn</dc:creator><description>&lt;p&gt;J&amp;oslash;rgen,&lt;br /&gt;&lt;br /&gt;Thank you so much, this is helpful!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial timeout issues with nrf_serial_read() and nrf_serial_write() with nrf_serial_mode_irq.</title><link>https://devzone.nordicsemi.com/thread/231734?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 15:05:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b3af45a-7cc9-459a-910b-f7592d33520a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I requested to convert the ticket to public space, you need to accept it before it is converted.&lt;/p&gt;
&lt;p&gt;1. This section refers to calling the APIs from interrupt context of other peripherals, it does not refer to the IRQ mode used in the nrf_serial library. I&amp;#39;m not sure how the library implements support for timeout=0. To me, it looks like this will generate a TIMEOUT error immediately, but I can have overlooked something in the code.&lt;/p&gt;
&lt;p&gt;2. I would recommend that you filter this error before passing the error code to APP_ERROR_CHECK() macro, for instance like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t read_bytes = 0;
ret_code_t err_code = nrf_serial_read(&amp;amp;serial_uart, &amp;amp;c, sizeof(c), &amp;amp;read_bytes, 1000);

if(err_code == NRF_ERROR_TIMEOUT)
{
    if(read_bytes &amp;gt; 0)
    {
        //Process received data
    }
    else
    {
        //Try read again
    }
}
else
{
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial timeout issues with nrf_serial_read() and nrf_serial_write() with nrf_serial_mode_irq.</title><link>https://devzone.nordicsemi.com/thread/231733?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 19:32:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:937957d9-0089-43b3-8de5-efd74c97d0a0</guid><dc:creator>nikostpn</dc:creator><description>&lt;p&gt;Hi Jørgen, &lt;br /&gt;&lt;br /&gt;First of all, I can make this question public, but I actually posted another question which has the same content, essentially, because I only got one notification when I was editing this post yesterday that it is under review and no further indications of what is happening to it, so I thought it got deleted. I think your answers are a bit more direct than the other engineer&amp;#39;s answers to the question and I would like to make this answer available to others too. What is the best way of going about that?&lt;br /&gt;&lt;br /&gt;Now, onto the actual questions: &lt;br /&gt;&lt;br /&gt;1. Oh, alright. I thought that in the documentation that is what was stated:&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-9d4a7e6a74c945e8970e0c0a02c0e709/pastedimage1580239774278v1.png" alt=" " /&gt;&lt;br /&gt;&amp;quot;Do not use synchronous API (timeout_ms parameter &amp;gt; 0) in IRQ context. It may lead to a deadlock because the timeout interrupt cannot preempt the current IRQ context.&amp;quot;&lt;br /&gt;&lt;br /&gt;2. That makes sense. Would I ignore the TIMEOUT error within the weak_error file or when the actual program runs without the debugger it doesn&amp;#39;t actually switch to NRF_BREAKPOINT? &lt;br /&gt;&lt;br /&gt;3. That makes sense, thank you.&lt;br /&gt;&lt;br /&gt;Thank you so much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial timeout issues with nrf_serial_read() and nrf_serial_write() with nrf_serial_mode_irq.</title><link>https://devzone.nordicsemi.com/thread/231732?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 16:13:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64ce01a4-8c28-40a0-8c4c-b7856e1b58d0</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1. If you put NULL, the timeout will expire immediately, causing the TIMEOUT error that you see. This is expected. How can increasing the timeout parameter lead to a deadlock?&lt;/p&gt;
&lt;p&gt;2. The&amp;nbsp;p_read parameter will indicate the number of received bytes. The NRF_ERROR_TIMEOUT error can be ignored if this is expected in your application. Setting the&amp;nbsp;SERIAL_BUFF_RX_SIZE parameter to 1 will configure the UART(E) peripheral to receive a single byte at a time and place this into the FIFO, making sure you do not miss any data. However, if you have many other high priority tasks that need to be handled in your application, this may block the serial library from updating the buffer pointer fast enough. An alternative can be to use the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_libuarte.html"&gt;async libUARTE library&lt;/a&gt;, which implements reliable communication over UART.&lt;/p&gt;
&lt;p&gt;3. The serial_rx/serial_tx functions will pull the data out of the queues. You can call the functions&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__serial.html#ga4912baad1dcc3d6fa4f05ad7b5acadbb"&gt;nrf_serial_flush&lt;/a&gt;()/&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__serial.html#ga16e23a5364f4c1f22f9abedc5b20b620"&gt;nrf_serial_rx_drain&lt;/a&gt;() to force this.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>