Hi,
I'm using the function sd_app_evt_wait() to go into low power mode, but it returns sooner than expected.
I tried to figured out which event that is the cause for that with sd_evt_get() before and after sd_app_evt_wait(), but it always return (NRF_ERROR_NOT_FOUND No pending events). I also checked the NVIC registers and, apparently, it is something related with the RTC1 or GPIOTE (but, I don't think it is the GPIOTE). But I've tried to do
NVIC_ClearPendingIRQ(GPIOTE_IRQn) and NVIC_ClearPendingIRQ(RTC1_IRQn) before sd_app_evt_wait() and it didn't work.
Here is the NVIC state before sd_app_evt_wait():
And here it is after sd_app_evt_wait():
Here is my main loop:
void loop(void)
{
nrf_drv_wdt_channel_feed(m_channel_id);
app_system_tasks();
app_ble_tasks();
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
(void) __get_FPSCR();
NVIC_ClearPendingIRQ(FPU_IRQn);
bsp_gpio_led_high();
APP_ERROR_CHECK(sd_app_evt_wait());
bsp_gpio_led_low();
}
But, what makes me confuse is that when I put a second sd_app_evt_wait() in sequence, it works just fine.
void loop(void)
{
nrf_drv_wdt_channel_feed(m_channel_id);
app_system_tasks();
app_ble_tasks();
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
(void) __get_FPSCR();
NVIC_ClearPendingIRQ(FPU_IRQn);
bsp_gpio_led_high();
APP_ERROR_CHECK(sd_app_evt_wait());
APP_ERROR_CHECK(sd_app_evt_wait());
bsp_gpio_led_low();
}
I used one LED to see the sleep time in comparison with the GPIOTE interruptions, as you can see below. The 'Channel 1' is the led state (1 - Power Down / 0 - Normal mode), while the others are GPIOTE interruptions.
Finally, here is the graph when I utilized two sd_app_evt_wait() in sequence. It is just as I expected, the microcontroller just waked with the interruptions.
How can I discover which event causes the return from sd_app_evt_wait()? Can it be something related with app_timer or with the watchdog as they use the RTC? But, I don't have any app_timer with a frequency comparable with the return from sd_app_evt_wait().