BGX-to-Phone Temp Sensor Demo
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.
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
The demo requires a Wireless Xpress BGX13P Starter Kit and an EFM8SB1 Starter Kit.
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.
Active mode current consumption is greatly reduced by setting the baud rate to 9600.
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.
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.
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.
The system clock is set to the low-power oscillator with a clock divider of 2 instead of a high-frequency oscillator.
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, MODE 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.
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.
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.68 uA. The SB1 will be woken up through a port match on PB1.
Host MCU Sleep and BGX Advertise with MODE 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 mA. Low duty cycle advertising will kick in if no connection is established within 5 seconds, dropping the current draw to around 51 uA. While the BGX is advertising, the SB1 is put back to sleep with a port match wake-up on the MODE PIN. The MODE PIN is set by gfu 6 str_active_n. MODE PIN is toggled whenever the BGX enters stream mode meaning the SB1 will only wake-up once the BGX is connected to via mobile app.
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 867 uA. The remaining 1.45 seconds, 72% of the period, is spent in sleep mode at 37 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 MODE PIN meaning it will wake up if it detects a BGX disconnection.
Current Measurement Flowchart
Simplicity Studio Energy Profiler Current Measurement