Using Low-Energy UART
The standard UART interface needs EM1 or EM0 energy modes even while waiting for an input byte. Staying constantly in EM1/EM0 mode results in a high energy consumption.
The Low Energy UART (LEUART) provides full UART communication running from a 32.768 kHz clock input. It allows UART communication down to EM2 and data transmission and reception using DMA.
Note: Because 32.768 kHz clock is used, the LEUART is limited to a 9600 maximum baudrate.
This example uses the LEUART Start Frame and Signal Frame features, which allow the LEUART to generate an interrupt upon receiving a pre-configured byte allowing enhanced energy savings and more control over which data the LEUART reads. Briefly, this is how the example operates:
Upon startup, the device advertises the LEUART example with the device name and enters EM2 in between advertisements. The LEUART is active waiting for the start frame, which is the character *, all other bytes are blocked.
After the start frame is received, an interrupt is generated and the string "Start Frame" is printed out using DMA. An additional DMA channel is set up to read incoming data to the LEUART.
When the signal frame # is received, the data read by the DMA is used to set the new device name, which is also printed out on the LEUART.
The device goes back into blocking other bytes and waiting for the start frame -> go back to (2).
Note: The DMA only copies 20 bytes after the start frame (including the signal frame). Therefore, if more bytes are sent, the 21st byte will have the same functional effect as sending the signal frame so that the LEUART doesn't become blocked.
Create a new SoC - Empty project for your device.
Copy the dmadrv folder, em_leuart.h/c and em_ldma.h/c files from the SDK directories (
C:\SiliconLabs\SimplicityStudio\versionX\developer\sdks\gecko_sdk_suite\versionY\platform) to the project
Add the included files to the project include paths (For example, for GCC: project -> Properties -> "C/C++ Build" -> Settings -> "GNU ARM C Compiler" -> Includes and project -> Properties -> "C/C++ Build" -> Settings -> "GNU ARM Assembler" -> Includes ):
Replace the existing app.c with the one attached here.
Change the device name to "LEUART Example" in the GATT Configurator (.isc) or import the attached gatt.xml. Remember to Save and Generate when you make a change.
Build and flash the project.
Changing the WSTK Baud Rate
The LEUART is limited to 9600 baud due to the low frequency clock that it runs from. To try this example using the WSTK VCOM, change its baud rate from the default 115200. It's also possible to connect an external UART<->USB converter instead of using the VCOM, in which case these instructions are not needed.
To change the WSTK VCOM settings, connect to the WSTK via serial port to access the board controller.
To change the settings through serial connection, use the console in Simplicity Studio:
Plug in your device and right click on it in the "Debug Adapters" pane.
Select "Launch Console" and navigate to the "Admin" tab.
After the console session is opened, you’ll be shown the WSTK command prompt. If you write serial vcom, it will print out the existing settings.
- Finally, to configure the settings, run the command serial vcom config handshake disable speed 9600. The output of the command can be seen in the figure below.
Serial Console Config
Running the Example
Start EFR Connect App on your smart phone and find your device in the Bluetooth Browser advertising as "LEUART Example"
Connect to the UART interface of your device with a terminal program (such as TeraTerm).
Type "\My Device#"* on the terminal.
Refresh the list of devices in the Bluetooth Browser of the EFR Connect App. Now, your device should advertise itself as "My Device".
The figure below shows what happens in the terminal when "\My Device#" is sent into the LEUART (*My Device# is sent to the LEUART and echoed on the terminal). A scanning device can see the device name as being My Device*.
The following figure shows the Energy Profiler with the larger current spike corresponding to the LEUART activity.