<?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>Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/32009/polling-mode-in-serial-library</link><description>Hello, 
 Can anyone point me to a good example for Polling mode using serial library? 
 I&amp;#39;m looking for an application in which I can poll the serial port for data. I went through API documentation and found that Serial library has a polling mode. Can</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Mar 2018 19:30:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/32009/polling-mode-in-serial-library" /><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124653?ContentTypeID=1</link><pubDate>Thu, 15 Mar 2018 19:30:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d0adec2-9086-4472-b1c8-86550afc9eb9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;When using the POLLING mode, the function calls&amp;nbsp;nrf_serial_read and&amp;nbsp;nrf_serial_write will not return until the operation is complete (the number of specified bytes have been transmitted or received), the timeouts will not be functional. If you do not write anything to the UART line, it will be stuck on the read if until the requested number of bytes are received. nrf_serial_flush will not have any effect in polling mode:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (p_serial-&amp;gt;p_ctx-&amp;gt;p_config-&amp;gt;mode == NRF_SERIAL_MODE_POLLING)
{
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124571?ContentTypeID=1</link><pubDate>Thu, 15 Mar 2018 12:24:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1648658a-d9b8-446a-832c-d9b96156ecec</guid><dc:creator>sprasad</dc:creator><description>&lt;p&gt;It does print the received data in the first iteration. It gets stuck only in the second iteration of the loop.&lt;/p&gt;
&lt;p&gt;Btw, I&amp;#39;m going with polling mode because the functionality I&amp;#39;m trying to achieve is very trivial and doesn&amp;#39;t need any complex&amp;nbsp;queues and interrupt handlers. I just have to read data from both UARTs at will and store them. An example or code snippet describing the nuances of this polling mode would be very helpful.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124461?ContentTypeID=1</link><pubDate>Wed, 14 Mar 2018 19:51:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2630668-289f-43cd-bd71-36fc8e87d9d5</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Is it stuck on the line on the first iteration of the loop, or on second/later run? Did you check the &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/25173/nrf52840-uart1-not-working-in-sdk-14/124285#124285"&gt;suggestion from Jakub&lt;/a&gt; in the other thread where you posted your issue? Why are you not checking the error codes from&amp;nbsp;nrf_serial_flush function calls?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124370?ContentTypeID=1</link><pubDate>Wed, 14 Mar 2018 13:01:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a16ee9a8-0a40-4582-b62c-acf9106ca73b</guid><dc:creator>sprasad</dc:creator><description>&lt;p&gt;When I entered debug mode with Seggar Embedded studio, I saw that the control is stuck at line no.6 (ret = nrf_serial_read(&amp;amp;serial0_uart, &amp;amp;c, sizeof(c), NULL, 1000)). If you can suggest some debugging approach that would help me debug this problem better, I can try that too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124343?ContentTypeID=1</link><pubDate>Wed, 14 Mar 2018 10:33:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc9a9ee2-c7b6-4679-9c7b-4b4f6971d4f5</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;How does it fail? Are you getting an error code from any of the function calls?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124214?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 16:10:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9dd9cce-4639-4526-b767-980fa35909f1</guid><dc:creator>sprasad</dc:creator><description>&lt;p&gt;Thank you for the guidance. I was able to read and write the data using polling mode.&lt;/p&gt;
&lt;p&gt;I tried to replicate the same approach while using both UART0 and UARTE1 and tried to read the data from both UARTS. I&amp;#39;m able to read first character of UART0 only and after that the program gets stuck. Here is the code. Can you please suggest what could be done to overcome this?&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;// UART0 -&amp;gt; RX_PIN_NUMBER, TX_PIN_NUMBER (DEFAULT)
//UARTE1 -&amp;gt; ARDUINO_SDA_PIN, ARDUINO_SCL_PIN (DEFAULT)
        
        //In a loop
        
        ret = nrf_serial_read(&amp;amp;serial0_uart, &amp;amp;c, sizeof(c), NULL, 1000);
        if (ret != NRF_SUCCESS)
        {
            continue;
        }
        (void)nrf_serial_write(&amp;amp;serial0_uart, &amp;amp;c, sizeof(c), NULL, 0);
        (void)nrf_serial_flush(&amp;amp;serial0_uart, 0);
        
        ret = nrf_serial_read(&amp;amp;serial1_uart, &amp;amp;c, sizeof(c), NULL, 1000);
        if (ret != NRF_SUCCESS)
        {
            continue;
        }
        (void)nrf_serial_write(&amp;amp;serial0_uart, &amp;amp;c, sizeof(c), NULL, 0);
        (void)nrf_serial_flush(&amp;amp;serial1_uart, 0);
        (void)nrf_serial_flush(&amp;amp;serial0_uart, 0);
        &lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;&lt;span class="Apple-converted-space"&gt;On commenting out each uart sections individually, the code works fine. Only when i put both together, it fails! What might be the reason?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Polling Mode in Serial library</title><link>https://devzone.nordicsemi.com/thread/124196?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 14:41:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1de4b7ff-692e-46bf-918d-16ace4c9f7b6</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not aware of any examples of using polling mode, but this should be quite straight forward. You can start with the serial example, and modify it to your needs. You need to change the configuration as described in the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/lib_serial.html?cp=4_0_0_3_37"&gt;documentation&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;div&gt;&lt;code&gt;&lt;a title="Creates an instance of serial port configuration." href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/group__nrf__serial.html#ga2fa22c0832160f75d69f71deaa33a345"&gt;NRF_SERIAL_CONFIG_DEF&lt;/a&gt;(serial_config_polling, &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/group__nrf__serial.html#gga28d42a6ff602c49e23e9cf1b85d1df8ba2a369e6eadd464dc5d90bc1e7d4864e6"&gt;NRF_SERIAL_MODE_POLLING&lt;/a&gt;,&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;NULL, NULL, NULL, NULL);&lt;/code&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div&gt;Polling mode does not use&amp;nbsp;QUEUES,&amp;nbsp;BUFFERS,&amp;nbsp;EVENT_HANDLER, or&amp;nbsp;SLEEP_HANDLER, so you can remove all defines of these. You then need to call&amp;nbsp;nrf_serial_write() and&amp;nbsp;nrf_serial_read() to write and read the UART. The UART driver will operate in blocking mode, waiting for the operation to complete.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Best regards.&lt;br /&gt;Jørgen&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>