Energy Modes with Bluetooth Stack#

Background#

This code example has a related User's Guide here: Using Energy Modes with Bluetooth Stack.

Description#

Let us implement the following project so that it requires as little energy as possible:

  1. After resetting the device, a number has to be read in from UART between 0 and 9. Let it be n.

  2. If n=0, the device can go to sleep and needs to wake up only on reset. Go to step 1.

  3. If n>0, an iBeacon type advertisement has to be broadcast for n seconds.

  4. 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.

  1. In the first step, UART controller has to work continuously, which means that at least EM1 Sleep mode is needed.

  2. 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.

  3. 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.

  4. 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.

Setting up#

  1. Create a new SoC-Empty project for your device.

  2. Copy the attached app.c file into your project (overwriting the existing one).

  3. Copy the following files from the SDK folder (e.g: *C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.7*) into your project, under the same folders:

    • ..\platform\emdrv\uartdrv\src\uartdrv.c

    • ..\platform\emdrv\uartdrv\inc\uartdrv.h

    • ..\platform\emdrv\dmadrv\src\dmadrv.c

    • ..\platform\emdrv\dmadrv\inc\dmadrv.h

    • ..\platform\emlib\inc\em_leuart.h

    • ..\platform\emlib\src\em_leuart.c

    • ..\platform\emlib\inc\em_ldma.h

    • ..\platform\emlib\src\em_ldma.c

    • ..\platform\emdrv\gpiointerrupt\src\gpiointerrupt.c

  4. Add the missing include paths in the project settings. In SoC-Empty the example the only folder not added should be: "${workspace_loc:/${ProjName}/platform/emdrv/uartdrv/inc}"

  5. In the app.h set the DEBUG_LEVEL to 1.

  6. Build the project and flash it to the device.

Usage#

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:

Figure 2Figure 2

Source#