SAMD21 wake up time from deep sleep

Hi Steve,

Will the sleep be delayed until the SYNCBUSY is complete in that instance or does the device go to sleep right away?

In the absence of any information in the SAMD21 datasheet, I decided to run a small test that wrote to the RTC's write synchronised ALARM0 register, called the __WFI() (Wait For Interrupt) function to put the microcontroller into deep sleep, but used RTC's the SYNCRDY interrupt to wake the process once synchronisation was complete.

It turns out that the RTC's interrupt service routine (ISR) is called exactly 5.8ms after going to sleep, indicating that synchronisation process continues in the RTC during despite being in standby.

However, the SAMD21 didn't behave entirely as expected. The microcontroller wakes up after only 3ms, (before the 5.8ms has elapsed) and starts executing the loop() code before calling the ISR. Furthermore, it enters the loop() before the synchronisation SYNCBUSY bit has been cleared in the RTC's STATUS register. I don't think another interrupt causing this, because if I disable the SYNCRDY interrupt the microcontroller never wakes up from the __WFI() function.

I'm trying to investigate what exactly is going on, as normally I'd expect the WFI() function to wake up the microcontroller and enter the ISR() directly after receiving an interrupt.

As you mention, it might be worth activating the event system and using the __WFE() (Wait For Event) function instead.

Kind regards,
Martin