<?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>UART Stopping</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10770/uart-stopping</link><description>We have noticed an issue when using the UART on our nRF51822 (SoftDevice = S130, nRF51_SDK_9.0.0_2e23562). Our Nordic app waits for commands on the UART and processes these commands when they come in. A Linux host app sends these commands periodically</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Dec 2015 16:45:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10770/uart-stopping" /><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40249?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 16:45:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1797bad8-51ce-4f22-a5d2-807555fd6d8c</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I think you ought to be able to just hammer the thing into the ground constantly without any kind of wait and it shouldn&amp;#39;t hang on you. So if it does hang, it sounds like a bug to me and it shouldn&amp;#39;t do it.&lt;/p&gt;
&lt;p&gt;&amp;#39;wait after fail&amp;#39; is how the API was designed to be used and is much lower power and generally less brutal way to do it so you should do that anyway as you are doing.&lt;/p&gt;
&lt;p&gt;So my slightly unhelpful take on it is that if it hangs when you just call it repeatedly without waits thats buggy, however if it works when used in a more anticipated way using waits when the uart reports it&amp;#39;s not yet ready before trying again, that&amp;#39;s how it was designed to work and you should be pretty confident using it that way; as well as it just being a good power-saving practice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40245?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 16:34:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a517245-a1f3-4e9d-9fdf-2a32dd9046fb</guid><dc:creator>Mark J</dc:creator><description>&lt;p&gt;Sorry - misread on my part. Understand the differences. We have also added the sd_app_evt_wait() after the while condition and this is what made the difference for us. So, I guess what I am left understanding is that without the sd_app_evt_wait(), we were &amp;quot;banging&amp;quot; the uart and that caused our issue and is expected behaviour.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40244?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 16:23:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:832c4771-d362-467f-8e19-951097be2afc</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;well actually no - that&amp;#39;s not what the code I posted does - mine does not bang on the uart, If the call returns NRF_SUCCESS then it processes, else it does an app event wait and only then tries again. So it loops, throttled by events, until it gets a character.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s different from the other two possibilities your original message allows (since you didn&amp;#39;t post any code) which are&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;just call app_uart_get() in a loop constantly until it returns NRF_SUCCESS. That&amp;#39;s what I describe as &amp;#39;banging&amp;#39; the uart.&lt;/li&gt;
&lt;li&gt;call app_uart_get() and then always follow it with sd_app_evt_wait() whatever it returns, which is what your original message hints you&amp;#39;re actually doing.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;1 is pretty brual, should work, but not great practice. 2. has more waits than needed but will return shortly after a new input. What I posted attempts to follow the documentation of the function and wait only when necessary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40248?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 16:11:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2d271d3-61c1-4d39-81bf-83c98e35f775</guid><dc:creator>Mark J</dc:creator><description>&lt;p&gt;The while loop enclosing the app_uart_get() call ... just as you have shown it and just as it is shown in countless examples. &amp;quot;if the call returns something other than success you bang on it again and try to get it again in tight loop?&amp;quot; ... isn&amp;#39;t that what &amp;quot;while( app_uart_get( .. ) != NRF_SUCCESS )&amp;quot; does?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40247?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 07:05:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0a274d0-ccf6-431b-aa95-178537e75afe</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;&amp;quot;staying in the while loop&amp;quot;&lt;/p&gt;
&lt;p&gt;What while loop? There&amp;#39;s a whole range of ways you could have written it. Are you saying you&amp;#39;re just banging repeatedly on the uart trying to get a character, if the call returns something other than success you bang on it again and try to get it again in tight loop?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40246?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2015 06:19:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a8022d0-1b02-4b24-b443-8997c4cef3aa</guid><dc:creator>Mark J</dc:creator><description>&lt;p&gt;Thank you RK for replying.&lt;/p&gt;
&lt;p&gt;app_uart_get() is just reading byte for byte as all examples show. In this specific case, it appeared to be returning with a result other than NRF_SUCCESS and staying in the while loop (before we added sd_app_evt_wait() as shown in examples and in your reply above). This has to be the case as sd_app_evt_wait() calls have fixed our issue. What we are really trying to understand is why the addition of sd_app_evt_wait() makes a difference. This is important to us so that we can understand if our issue has been resolved. To clarify, after adding the sd_app_evt_wait() call - the UART no longer seems to stop. We would just like to understand why or how the addition of this call makes a difference to feel comfortable that the issue is completely resolved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART Stopping</title><link>https://devzone.nordicsemi.com/thread/40243?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2015 01:30:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98891425-2def-470d-96f7-41feb1d0c80c</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;What is app_uart_get() doing before you add the app event waits? Is it returning an error code or not returning at all or what? The documentation for that function tells you that if there&amp;#39;s no character to read then it returns an error code and will generate an event when a byte comes in. The event coming in would trigger sd_app_evt_wait() to return so I can see how putting them in might be working, however what you should be doing is reading the character, if one is returned, processing it, if it&amp;#39;s an error returned, then use sd_app_event_wait()&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while( app_uart_get( .. ) != NRF_SUCCESS )
    sd_app_evt_wait()
// process your character here
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;more like that&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>