<?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>non blocking delay</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/32871/non-blocking-delay</link><description>Hi, 
 I work with a ship nrf52832. 
 I try to realise a communication beetween an UART sensor and the ship. 
 When i send my command ( app_uart_put) , i use nrf_delay_ms fonction to wait the answer and synchnise my communication. 
 But during the delay</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 May 2018 15:20:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/32871/non-blocking-delay" /><item><title>RE: non blocking delay</title><link>https://devzone.nordicsemi.com/thread/130643?ContentTypeID=1</link><pubDate>Wed, 02 May 2018 15:20:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0fea201-f239-4610-84f5-fe8f7fd0eae6</guid><dc:creator>Moe</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;As AmbystomaLabs said, using nrf_delay_ms() or nrf_delay_us() will block other functions from being executed, eg. UART TX/RX, another work around is to create an application timer, there is an example tutorial for this on the website. try to search it and it will popup.&lt;/p&gt;
&lt;p&gt;note that this tutorial is not up-to-date so you have to modify it. e.g. APP_TIMER_INIT() is mentioned in sdk13+ but the actual function for this is app_timer_init(); notice the difference.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;just to give you some hints:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;- APP_TIMER_DEF(timer_id); //create a timer id&lt;/p&gt;
&lt;p&gt;-void timer_event_handler(void *p_context){ // do your things here};&lt;/p&gt;
&lt;p&gt;-initialize the timer and it should be statically allocated e.g.:&lt;/p&gt;
&lt;p&gt;static void init_timer(void)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_code_t err_code = app_timer_init();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;- create the timers and and then start it check the options by creating and statically allocating it:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;static void start_timers(void)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_code_t err_code;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; err_code = app_timer_create(&amp;amp;timer_id, APP_TIMER_MODE_REPEATED, timer_event_handler); // can also use the single shot mode&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; err_code = app_timer_start(timer_id, APP_TIMER_TICKS(2000), NULL); //e.g. for 2000 ms&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Now in the main() do the following&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;1 - first thing first: call the init_timer();&lt;/p&gt;
&lt;p&gt;2- start the timers: call start_timers();&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;this is how it worked for me, I hope i could have helped as I also struggled with the tutorial since its a bit old and am also in my first steps.&lt;/p&gt;
&lt;p&gt;regards,&lt;/p&gt;
&lt;p&gt;Moe&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non blocking delay</title><link>https://devzone.nordicsemi.com/thread/126358?ContentTypeID=1</link><pubDate>Wed, 28 Mar 2018 21:14:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d399e0b5-b8be-4281-89a5-c70eb7cf6f17</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;The nrf_delay function uses __NOP(); (ie, no operation) repeatedly to affect the delay. It is kind of a lazy approach to a delay function.&lt;/p&gt;
&lt;p&gt;Since this holds up the processor, I would assume the UART comms are getting lost. The UART uses DMA to pass the data to the processor but likely the UART driver is held up or slowed down while your delay runs.&lt;/p&gt;
&lt;p&gt;You can use the app timer to make a timer that uses the hardware timers for your delay.&amp;nbsp; The hardware timers don&amp;#39;t affect the processor activity. Or you can build the thing by hand using the timers and UART events to make your delay.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>