BGX-to-Phone Temp Sensor Demo
Overview
Bluetooth Xpress makes it possible to add Bluetooth to any MCU with minimal knowledge of wireless connectivity. A simple use case scenario would be a temperature sensor sending the temperature to a mobile app through BLE managed behind the scenes. This example serves to demonstrate the speed and ease of getting started with BGX development. This page will go over what the demo does, the hardware required to run the demo, and highlight all the low power features.
Demo Functionality
This demo collects and sends temperature sensor data to the BGX Commander iOS or Android app. It begins by initializing the host MCU and BGX . The user begins the demo by pressing push button 1 (PB1) on the host MCU. The host MCU will send an advertise command to the BGX via UART. This allows the mobile app to find the BGX and connect to it. Once connected, the host MCU will continue to collect and send temperature readings to the mobile app every 2 seconds. The temperature reading will revolve around a 1-point calibration that resides in the MCU flash memory. The user can write a 1-point calibration to the MCU using BGX Commander. If the MCU detects this incoming calibration data, it will recalibrate the temperature based on the user's new 1-point calibration. All low power features integrated within this process are discussed later.
Temp Sensor Demo Flowchart
Hardware
This demo uses a Wireless Xpress BGX13P Starter Kit and an EFM8SB1 Starter Kit. Any devices in the Wireless Xpress BGX family can be substituted in for the BGX13P in this demo.
Wireless Xpress BGX13P Starter Kit
This Wireless Xpress Starter Kit includes the Bluetooth Xpress BGX13P module and serves as a starting point to build applications for BGX. The BGX demo makes use of the starter kit's expansion header allowing for communication between the two starter kits. More guidance on this starter kit can be found in the User Guide , the BGX13P Data Sheet , and the BGX Development App Note .
EFM8SB1 Starter Kit
This MCU Starter Kit can serve as a starting point for host application development. The BGX demo makes use of the starter kit's push buttons, temp sensor, expansion header, and low power features. More guidance on this starter kit can be found in the User Guide , the Data Sheet , and the Schematic .
Expansion Header Communication
The two starter kits are connected through a 20-pin expansion header. This allows power, serial communication, and other pins to be routed over from each board. The pins routed over the expansion header essential to the demo are shown below.
Low Power Features
The demo includes a variety of power saving features. Power can be saved from both sides, the BGX and the EFM8SB1. The methods to achieve this are described below.
BGX
Baud Rate
Active mode current consumption is greatly reduced by setting the baud rate to 9600.
Sleep Mode
Sleep mode is set whenever the BGX is not advertising or connected. This allows the radio to completely shut off. Sleep mode can be entered and left through sleep and wake .
BLE Advertising
BGX module advertises in a high-duty cycle for a short duration and then stays at a low-duty cycle. The default high-duty cycle advertising duration is 30 seconds. Use the variable bl v h d , to control high-duty cycle duration. The faster the BGX module switches into the low duty cycle advertising, the more power can be saved.
BLE Connection Interval
The Default BLE connection interval is 15 ms. Increasing the BLE connection interval reduces power consumption. Use bl c i to increase connection interval.
EFM8SB1
ADC
Low power mode is enabled by setting ADLPM in the ADC power control register. This is only possible with a slow sample rate which this application has. A slower ADC sample rate allows for reduced power. Additionally, the ADC remains off until a temperature measurement is needed.
LED
SB1 LED0 shares a pin with BGX BTN1 so LED0 defaults to on. Removing LED0 eliminates the power consumption of the LED and a pull-up resistor.
Clock Control
The system clock is set to the low-power oscillator with a clock divider of 2 instead of a high-frequency oscillator.
Sleep Mode
Setting the sleep mode select bit in the PMU0CF register turns off the internal 1.8 V core LDO regulator and power to most digital logic on the chip. There are a few ways the SB1 can wake-up from sleep and these wake-up sources need to be specified before going to sleep. The wake-up sources used in the demo are RTC alarms and port match events. RTC alarms are generated synchronously with a defined time set in firmware. This is set to 2 seconds in the demo. Port match events are generated asynchronously whenever a specified pin is toggled. The pin and its base state are defined in the firmware as well. The port match pins used in the demo are SB1's PB1, CONNECTION PIN, and UART RX. Different parts of the demo require different permutation of these wake-up sources. The specific permutations required for each section will be discussed below.
Current Measurements
This demo can be split into 4 sections when discussing power consumption. These 4 sections are represented as dashed boxes in the current measurement flowchart . The sections and their respective current measurements are discussed below.
Initializations
The beginning initializations show a glimpse of both starter kits' default power management. It remains around 5 mA until the baud rate for the serial communication is initialized to 9600.
Host MCU and BGX Sleep with PB1 Port Match
Once initialization is complete, the host MCU and BGX are put into sleep mode. During sleep the average current draw is around 2.49 uA. The SB1 will be woken up through a port match on PB1.
Host MCU Sleep and BGX Advertise with CONNECTION PIN Port Match
The BGX will be woken up through a wake command sent by the recently awoken SB1. Once PB1 is pressed, the BGX begins advertising through an advertise command. It defaults to a high duty cycle averaging around 2.20 mA. Low duty cycle advertising will kick in if no connection is established within 5 seconds, dropping the current draw to around 100 uA. While the BGX is advertising, the SB1 is put back to sleep with a port match wake-up on the CONNECTION PIN. The CONNECTION PIN is set by gfu 6 con_active_n . CONNECTION PIN is asserted when BLE is connected meaning the SB1 will only wake-up once the BGX is connected to via BGX Commander.
Collect and Send Temperature and Host MCU Sleep with RTC Alarms and Port Matches
Once connected, the demo will enter its main loop where the SB1 will continue to read ADC temp data, write it to the BGX, and sleep in a cycle. The period of this cycle is around 2 seconds as seen in the Energy Profiler capture . The host MCU spends 0.55 seconds turning the ADC on, collecting data, and sending it serially via UART with an average current draw of 880 uA. The remaining 1.45 seconds, 72% of the period, is spent in sleep mode at 48 uA. The SB1 is woken up from sleep mode in 3 ways for this part of the demo. One way is through an RTC alarm which occurs every 2 seconds. Another way is through a port match on UART RX meaning it will wake up if it receives a 1-point calibration from BGX Commander. The final way is through a port match on the CONNECTION PIN meaning it will wake up if BGX Commander disconnects from the BGX.
Current Measurement Flowchart
Simplicity Studio Energy Profiler Current Measurement