When it is expected that there are big pauses between activity, for instance a sensor providing new readings only every second or minute, it becomes a

Rise and Shine: Putting the nRF52840 to sleep, and waking it back up

submited by
Style Pass
2021-06-12 11:00:07

When it is expected that there are big pauses between activity, for instance a sensor providing new readings only every second or minute, it becomes attractive to enable the device's power saving mode: the device is put to sleep when we know the next activity will not happen for a while, and woken up when it needs to perform work again.

The idea is straightforward, but implementation proved less so. At Tweede Golf we use Rust for embedded development, but the relevant rust crates do not currently expose the functionality we need for this task in a convenient (and discoverable) way.

First we take ownership of the peripherals. The compiler makes sure there is only ever one owner of the peripherals. That is a best practice, especially when considering that execution can be interrupted at (almost) any moment. When the interrupt handler uses the same peripheral as user code, the result is undefined and the application may crash. Next, we set the systemoff register of the POWER peripheral.

When ran, the device will enter "System OFF" mode, the deepest power saving mode of the nRF52840. This will terminate all ongoing tasks, which has two consequences:

Leave a Comment