Hello,
I’m working on nRF52840’s power management and I want to develop a sleep mode state that wakes the board up from RTC, for example, sleep for 10 seconds and wake up. I successfully managed to put it into a sleep mode using __WFE() “Wait for Event” function, however, the only way I can wake it up is from GPIO event, like pressing a button.
I guess the module has no RTC configuration, so I chose the Z-TIMER for seconds counter. How can I set into sleep mode and wake up on RTC using Z-TIMER?
I have tried calling ZTIMER and __SEV() after __WFE(), also writing direclty into memory, but with no success.
1 Like
Hi and welcome!
IIRC the nRF52 does a lot of automatic power management in hardware. Is a ztimer_sleep(ZTIMER_MSEC, 10 * MS_PER_SEC)
not sufficient for your use case?
Thank you for answering!
Unfortunately the board is not saving any power when I set ztimer_sleep(ZTIMER_MSEC, 10 * MS_PER_SEC)
. On Idle mode it measures 4 mA consumption and on sleep mode it is about 1.5 mA, but it doesn’t change on ztimer call, only when __WFE() is called.
void timer(void)
{
NRF_POWER->TASKS_LOWPWR = 1;
#ifdef MODULE_ZTIMER_USEC
ztimer_sleep(ZTIMER_MSEC, 10000);
#endif
__SEV();
}
void nrf52_sys_on(void) {
/* Clear Event Register */
__SEV();
/* Wait for event */
__WFE();
/* Wait for event */
__WFE();
}
void pm_set(unsigned mode)
{
switch (mode) {
case 0:
//GPIO wake up source sleep
nrf52_sys_on();
break;
case 1:
//RTC wake up source sleep
nrf52_sys_on();
timer();
break;
default:
//no sleep
break;
}
}