This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Wakeup from RTC only

Hello -

We are developing an application for nRF52840, using the v17.0.0 SDK. The application is running on FreeRTOS. We need to power off all the RAM and use the RTC to wakeup after a specified time. To do that I borrowed the SDK tickless idle code. Here is the part that configures the RTC and waits for the wakeup:

nrf_rtc_cc_set(portNRF_RTC_REG, 0, wakeupTime);
nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0);
nrf_rtc_int_enable(portNRF_RTC_REG, NRF_RTC_INT_COMPARE0_MASK);

__DSB();
    
do {
	__WFE();
} while (0 == (NVIC->ISPR[0] | NVIC->ISPR[1]));

The code works fine. My question is whether or not the code only wakes up on the RTC event, or can other/external sources trigger the wakeup condition? If other sources can trigger the wakeup, how can the do/while loop be modified to only exit when the RTC event triggers?

Also, when the SoftDevice is enabled, we replace the loop above with a call to sd_app_evt_wait(). Similar question: does the call to sd_app_evt_wait() need to be bracketed with other tests to ensure that the RTC is the wakeup source?

Regards,

Brian

Parents
  • Hi 

    Using __WFE() or sd_app_evt_wait() will wake you up on any interrupt that occurs, assuming that interrupt is enabled through the interrupt controller, that is correct.  

    The normal way to handle this is to implement the interrupt handler, and set a flag or run some other code there. Then you can check this flag in your while loop, and only exit when the flag is set. 

    Best regards
    Torbjørn

  • Torbjørn -

    Thank you for the reply. I noticed that the SDK RTC example shows how to specify an interrupt handler and reworked our code to use that technique. That worked well, but fails when I power off all the RAM, even when I store the RTC instance in one retained section of RAM.

    The code I originally shared works when powering off RAM, so I looked for another way to know if the interrupt triggered corresponds to the RTC. This seems to work:

    do {
    	__WFE();
    } while (!nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0));
    

    My hope is that the (inlined) function returns true when the counter compare interrupt fires. Would you agree?

    Regards,

    Brian

  • Hi Brian

    The code you sent should work fine, as long as the RTC event register is not cleared anywhere else. 

    Best regards
    Torbjørn

Reply Children
No Data
Related