<?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>Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54405/problem-with-sd_app_evt_wait-after-sd_clock_hfclk_request</link><description>Hi there 
 After initializing the SoftDevice S132 V6.1.0, I request the HF crystal by calling the function sd_clock_hfclk_request(): 
 
 Later in the code, after a BLE connection has been established (nRF being in peripheral role), I&amp;#39;m calling sd_app_evt_wait</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 Mar 2020 09:31:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54405/problem-with-sd_app_evt_wait-after-sd_clock_hfclk_request" /><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/240583?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2020 09:31:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00a8a9f5-2a3f-4895-b920-d2013e897a1b</guid><dc:creator>Remo</dc:creator><description>&lt;p&gt;Hi. This function simply waits for the stabilization time of the used crystal before it is checked if the crystal is running.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/239412?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 20:52:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7158a469-88c3-45ea-b002-3ba843094671</guid><dc:creator>Justin</dc:creator><description>&lt;p&gt;Hi Remo, May I know how did you take care of Errata 68?&lt;/p&gt;
&lt;p&gt;What does&amp;nbsp;// Workaround for errata 68 of nRF52832 rev. 1&lt;br /&gt; QT_wait_us(HFXO_STABLE_TIME_US); function do in your code?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any input would be greatly useful.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Justin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/221315?ContentTypeID=1</link><pubDate>Thu, 21 Nov 2019 12:33:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b15decb-243e-43fd-b769-e14530025390</guid><dc:creator>Remo</dc:creator><description>&lt;p&gt;Hi Bj&amp;oslash;rn&lt;/p&gt;
&lt;p&gt;Ah yes, I see. I should have read the documentation for sd_app_evt_wait() more precisely. My bad. Thank you very much for your help.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/221161?ContentTypeID=1</link><pubDate>Wed, 20 Nov 2019 18:30:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd803052-e114-421a-923e-2688ef0f4bd4</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Remo,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;looking at the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga11d88d38ac99fb72cde74c9385d36433"&gt;sd_app_evt_wait&lt;/a&gt;() documentation I see that the following is stated:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;In order to wake up from disabled interrupts, the SEVONPEND flag has to be set in the Cortex-M MCU&amp;#39;s System Control Register (SCR), CMSIS_SCB. In that case, when a disabled interrupt gets pended, this function will return to the application&amp;#39;s main thread.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;in addition to the following&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span&gt;The application must ensure that the pended flag is cleared using&amp;nbsp;&lt;/span&gt;&lt;a title="Clear Pending Interrupt." href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.0.1/group___n_r_f___n_v_i_c___f_u_n_c_t_i_o_n_s.html#gaaab82d624bd21852288a3a6ad178cec7"&gt;sd_nvic_ClearPendingIRQ&lt;/a&gt;&lt;span&gt;&amp;nbsp;in order to sleep using this function. This is only necessary for disabled interrupts, as the interrupt handler will clear the pending flag automatically for enabled interrupts.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; So in short your hunch was correct, you need to clear the pending interrupt prior to going to sleep.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Bjørn&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/220905?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 14:56:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2ba6866-ad4e-4129-9d3e-60b3fb0c8bc4</guid><dc:creator>Remo</dc:creator><description>&lt;p&gt;Yes, that&amp;#39;s right. We are calling these functions in a loop.&lt;/p&gt;
&lt;p&gt;Yes, the pending flag for the &lt;span&gt;SD_EVT_IRQn is set although the interrupt has been disabled. E.g. after the HFCLK is requested by calling sd_clock_hfclk_request(), the system event NRF_EVT_HFCLKSTARTED is returned and the pending flag for SD_EVT_IRQn is set. Is this an unexpected behavior?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Since we have not cleared the pending flag, the nRF woke up immediately after entering System ON low power mode. Is the correct flow after waking up from ON mode to fetch the occurred BLE and system events, clear the pending flag and enter ON mode again?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/220882?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 14:16:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29e94a18-53ae-4e7a-a986-5f2ac396a02c</guid><dc:creator>bjorn-spockeli</dc:creator><description>[quote user="Remosennhauser"]The functions sd_ble_evt_get() and sd_evt_get() return both the status NRF_ERROR_NOT_FOUND.[/quote]
&lt;p&gt;Ok, so there are no events ready to be pulled.&lt;/p&gt;
[quote user="Remosennhauser"]I think I may have found the problem. When the SD_EVT_IRQn is enabled, the pending flag is cleared automatically when the SD_EVT_IRQHandler is entered, right?[/quote]
&lt;p&gt;Ah ok, so you ve called sd_nvic_DisableIRQ(SD_EVT_IRQn) and are then just calling &lt;span&gt;sd_ble_evt_get() and sd_evt_get() in a loop? Yes, the pending interrupt should be cleared upon entering the&amp;nbsp;&lt;/span&gt;SD_EVT_IRQHandler.&amp;nbsp; But are you then getting a pending&amp;nbsp;&lt;span&gt;SD_EVT_IRQn interrupt after you have disabled it?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Bjørn&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/220737?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 08:38:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d567077e-5d93-4876-8e2d-0581ad9f85eb</guid><dc:creator>Remo</dc:creator><description>&lt;p&gt;Hi Bj&amp;oslash;rn&lt;/p&gt;
&lt;p&gt;The functions sd_ble_evt_get() and sd_evt_get() return both the status NRF_ERROR_NOT_FOUND.&lt;/p&gt;
&lt;p&gt;I think I may have found the problem. When the SD_EVT_IRQn is enabled, the pending flag is cleared automatically when the SD_EVT_IRQHandler is entered, right?&lt;/p&gt;
&lt;p&gt;But we have disabled the SD_EVT_IRQn and use the functions sd_ble_evt_get() and sd_evt_get() in polling mode. In that case, I assume that the pending flag is not cleared automatically when waking up from sd_app_evt_wait() and we have to do this ourselves. Is that correct?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with sd_app_evt_wait() after sd_clock_hfclk_request()</title><link>https://devzone.nordicsemi.com/thread/220383?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2019 16:50:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:366521e7-2e84-460d-86e7-ab90d4ba17ae</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Remo,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]I&amp;#39;ve read that sd_app_evt_wait() returns immediately when an event is pending, but I would have expected that the nRF enters the low power mode at the next call of this function. Did I get this wrong? Why does starting the HF crystal prevent the nRF from entering System ON low power mode? Do you know this behavior?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;I agree that having the HFCLK running should not prevent the nRF from going to System ON: Low power mode. HOwever, since there is a&amp;nbsp;SoftDevice event being generated, then it would be interesing to know which event this is.&amp;nbsp; &amp;nbsp;Could you place a breakpoint in the ble_event_handler for the SoftDevice that is registerd with&amp;nbsp;NRF_SDH_BLE_OBSERVER as this should be called when a SD event is generated and look at the (p_ble_evt-&amp;gt;header.evt_id when you enter the handler?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>