NRF9160 Power On Sleep Waking without Discrete Event or Interrupt

I am using a NRF9160 module using NCS 1.8.

My application is successfully using GNSS, HTTPS, and MQTT.  The issue I am currently having is premature wakeup from the POWER ON Sleep state.

I currently launch a oneshot timer with:

 k_timer_start(&my_one_shot_timer,  K_SECONDS(sleep_time), K_NO_WAIT );//one shot timer

Then I am placing the NRF9160 into sleep mode with 

__WFI();
__SEV();
__WFI();

The issue I am currently having is the unit wakes from sleep prior to the timer timeout.

I have confirmed the timer was still running by using this code after wakeup that I found on the forum.

if ((cnt = k_timer_status_get(&multi_shot_timer)) > 0) {
/* timer has expired */
printk("Timer count %d\n", cnt);
} else if (k_timer_remaining_get(&multi_shot_timer) == 0) {
printk("Woke without timer?");
/* timer was stopped (by someone else) before expiring */
} else {
printk("Timer still running");
/* timer is still running */
}

I have disabled UART interrupts in the config and am using RTT instead of serial to eliminate UART.

Is there a better way to put the device to power on sleep/idle?  Could the MQTT or Socket handlers be causing events to fire even though they aren't actively being called?  Should I just ksleep instead?

Parents
  • Hi

    Zephyr is an OS which will handle the idle state without any need to explicitly tell the CPU to enter sleep through WFI/WFE or similar. Whenever a thread is scheduled (e.g. using the k_timer library), the CPU exits the WFE state and returns back to WFE when the thread is finished (i.e. the callback function returns). Even the main() function can be returned; you don't have to have a main loop at the end. Zephyr will then return to the idle thread when all tasks are finished and it's waiting for the next interrupt. If you want to sleep for a specific amount of time inside a thread without returning, e.g. if you want to do some polling or similar, you can use k_sleep().

    Best regards,
    Stian

Reply
  • Hi

    Zephyr is an OS which will handle the idle state without any need to explicitly tell the CPU to enter sleep through WFI/WFE or similar. Whenever a thread is scheduled (e.g. using the k_timer library), the CPU exits the WFE state and returns back to WFE when the thread is finished (i.e. the callback function returns). Even the main() function can be returned; you don't have to have a main loop at the end. Zephyr will then return to the idle thread when all tasks are finished and it's waiting for the next interrupt. If you want to sleep for a specific amount of time inside a thread without returning, e.g. if you want to do some polling or similar, you can use k_sleep().

    Best regards,
    Stian

Children
Related