Energy Modes with Bluetooth Stack
This code example has a related User's Guide here: Using Energy Modes with Bluetooth Stack.
Let us implement the following project so that it requires as little energy as possible:
After resetting the device, a number has to be read in from UART between 0 and 9. Let it be n.
If n=0, the device can go to sleep and needs to wake up only on reset. Go to step 1.
If n>0, an iBeacon type advertisement has to be broadcast for n seconds.
When ready, the device can go sleep, but when a new character – any character – is received on UART, it has to wake up, and read in a number (n) again. Go to 2.
First, consider the required energy modes.
In the first step, UART controller has to work continuously, which means that at least EM1 Sleep mode is needed.
If n=0, the device can go to sleep. Because operation is not needed and a reset will wake up the device, the device can be put into EM4 Shutoff.
If n>0, the device starts broadcasting. However, operation is not needed between sending two packets and only RTCC has to run, which ensures wake-up in time, and is counting the elapsed time since start. RTCC needs EM2 Deep Sleep, hence the device can be put into EM2 Deep Sleep mode between two packets.
When all packets are sent out, there is no need for stack operation and the device can be put into EM3 Stop. If an interrupt is set for the transition of the Rx pin, the device can be woken up with any incoming UART signal and the next received character can be read in.
Find attached the project that implements this functionality using the functions discussed in this article.
Create a new SoC-Empty project for your device.
Copy the attached app.c file into your project (overwriting the existing one).
Copy the following files from the SDK folder (e.g: C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.7\platform) into your project:
In the app.h set the DEBUG_LEVEL to 1.
Build the project and flash it to the device.
Open a terminal program of your choice on the computer. After reseting the device, you should see the "OK" message on your screen, which shows that the device init is complete. After that you can send the time interval values via the terminal, as mentioned in the description chapter. If you profile the project with Energy Profiler, you should see the following: