Using EM3/EM4 in a Beacon App
This document shows the use of sleep modes EM3 and EM4 in a Bluetooth Beacon Application. The use case addressed in the attached example code is that of a Bluetooth Beaconing device, which operates in deep sleep mode EM3 or EM4. When the user interrupts the operation via a Button press, the device advertises for 10 seconds and goes back to sleep.
For more information about using Energy Modes with Bluetooth Stack, see this article: Using Energy Modes with Bluetooth Stack.
The attached example works with any board which has Button 1 mapped to pin PF7. Take a look at this Excel sheet for Button 1 mapping: Button mapping
Create "SoC Empty" example for your radio board.
Copy and overwrite the attached files into the project directory.
Copy GPIO interrupt source files from SDK installation tree to your project directory from source directory: C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\
Copy the following files to your project - if they are not added yet:
This will start the example main loop instead of running the default main loop of the SoC-empty example.
Compile and flash the attached example code on an EFR.
Set the WSTK in AEM mode using the 3-way switch.
In Simplicity Studio, open Energy Profiler.
On the top left under Quick Access -> Start Energy Capture.
Press Reset on the WSTK.
See the graph generated for the energy consumption.
Press PB1. The device will advertise an iBeacon Packet for 10 seconds. During this time, the user will notice a jump in power consumption. The device falls back to deep sleep after 10 seconds.
Note that if the device goes EM4 very soon after reset, it may be hard to get attached to the target using debugger and you can easily lock yourself out. The attached program has a 10 sec delay at boot to avoid this situation.
To initialize a device for EM4:
EMU_EM4Init_TypeDef int_EM4 = EMU_EM4INIT_DEFAULT; EMU_EM4Init( &int_EM4 );
Define a wakeup pin to exit from EM4. This command enables wake up using GPIO pin in an active low state.
You can only exit EM4 via a reboot. In EM3 or higher modes, the applications will continue execution from where it left off before entering sleep.
GPIO_EM4EnablePinWakeup( GPIO_EXTILEVEL_EM4WU1, 0 );
To enter EM4:
Unlike EM4, the other sleep modes cannot be entered by executing the command. If deep sleep flags are enabled, the device by default tends to go to the lowest allowed mode till EM3 where lower mode is lower energy consumption. The only thing which remains is to unblock the use of EM3. To end EM3 blocking call.
In the example code attached, use 3 and 4 in this define statement to switch between EM3 and EM4 respectively.
#define ENERGY_MODE 3
The average current consumption in EM3 deep sleep mode is 2.34 uA.
The average current consumption in EM4 deep sleep mode is 240 nA.