Serial-to-BLE Opening the Box
This video provides a walk through explanation of the API library tool for Serial-to-BLE, highlighting how to easily sort and search to find the API command you need. It also details how to download the auto-generated C code for your host MCU from right within the tool. (4:34)
This short video reviews the various options and settings related to establishing a connection with your SaBLE-x development board via USB. (2:14)
This video provides an overview of the PC Host for Serial-to-BLE tool, which allows the developer to set up their PC to act as a Host to talk to the SaBLE-x module using the Serial-to-BLE API for evaluating the API and troubleshooting your design. (3:27)
This tutorial walks through the powerful PC Host Script Tool, which allows a developer to chain a sequence of commands together, without any time spent coding the host MCU. It also highlights a number of the useful sample scripts that LSR has included with this tool. (16:31)
The PC Host Script Tool provides the capability to create scripts combining multiple Serial-to-BLE commands into a specific sequence. The Developer Tool Suite includes over 20 Test Scripts already available. The following table provides a description of those LSR-provided Test Scripts.
Test Scripts can be found within the PC Host Script Tool by clicking on Open, and then following this path:
Script Name | Description | Device(s) |
SaBLE-x_TestScript_1 | Script used to test the advertsing LED behavior. | Peripheral only |
SaBLE-x_TestScript_2 | Script used to test the heartbeat LED behavior. | Peripheral only |
SaBLE-x_TestScript_3 | Script used to test all the set baud rate command. | Peripheral & Central |
SaBLE-x_TestScript_4 | Script used to connect devices at min connection interval. | Peripheral & Central |
SaBLE-x_TestScript_5 | Script used to connect devices at max connection interval. | Peripheral & Central |
SaBLE-x_TestScript_6 | Script used to connect devices at default connection interval. | Peripheral & Central |
SaBLE-x_TestScript_7 | Script used to send OTA data min payload, both hex and ASCII, both directions. | Peripheral & Central |
SaBLE-x_TestScript_8 | Script used to send OTA data max payload, both hex and ASCII, both directions. | Peripheral & Central |
SaBLE-x_TestScript_9 | Script used to test the default settings. | Peripheral only |
SaBLE-x_TestScript_10 | Script used to test minimum values. | Peripheral only |
SaBLE-x_TestScript_11 | Script used to test maximum values. | Peripheral only |
SaBLE-x_TestScript_12 | Script used to test minimum string lengths. | Peripheral only |
SaBLE-x_TestScript_13 | Script used to check for memory leaks on messages that requrie the entire script to be looped. | Peripheral only |
SaBLE-x_TestScript_14 | Script used to test soft reset. | Peripheral only |
SaBLE-x_TestScript_15 | Script used to test wake host option. | Peripheral only |
SaBLE-x_TestScript_16 | Script used to test wake host option. | Peripheral only |
SaBLE-x_TestScript_17 | Script used to check for memory leaks on peripheral only messages. | Peripheral only |
SaBLE-x_TestScript_18 | Script used to check for memory leaks on common messages. | Peripheral & Central |
SaBLE-x_TestScript_19 | Script used to send invalid OTA host messages. | Peripheral & Central |
SaBLE-x_TestScript_20 | Script used to test the UART LED behavior | Peripheral only |
SaBLE-x_TestScript_21 | Script to test if the peripheral sends wake host notifications when receiving OTA data | Peripheral & Central |
This guide will explain how to use the C code generated for a SaBLE-x host processor. The Developer Tool Suite lets a user export C code for a host processor that includes all commands in the Serial-to-BLE API.
Please see the Serial-to-BLE API Overview in order to gain an understanding of the Serial-to-BLE API and JSON-RPC.
To generate the C code that should be included in the host processor project, open the Serial-to-BLE API in the Developer Tool Suite, and click the "Generate Host C Code" button.
The Developer Tool Suite will save all the C files to a folder the user specifies. These C files can then be used in a host processor C project.
First, the generated C code will need to be included in the host processor project.
All API messages sent from the host to the module will be found in the C files containing "OutgoingMsg". For example, the QueryFirmwareVersionOut message looks like:
The JSON library (json.c and json.h) provide functions for building JSON-RPC messages. The auto-generated C code builds the QueryFirmwareVersion message using the json_mkobject, json_append_member and json_stringify methods from the json.c library. All API messages are implemented in the auto-generated C code so the end user does not have to worry about properly formatting and building the JSON-RPC messages.
To finish implementing this function, the user should add some code in between the App Code Start and End comment to send the pTemp char[] out the host processor's UART peripheral. Adding a function to send the null-terminated pTemp string might look like:
Now the QueryFirmwareVersionOut function can be called to send the message to the module.
The UartProcessor_WriteTxMessage function is responsible for adding the CRC to the end of the JSON-RPC message and sending it out the UART. The UartProcessor_WriteTxMessage function might look like:
Receiving bytes over the UART and framing a message is handled outside of the C code generated by the Developer Tool Suite. Some example code is provided below to properly frame a JSON-RPC message from a stream of bytes over a UART.
In the example, uartProcessor.c is a FreeRTOS task designed to process data placed into a circular buffer by the MSP430 UART peripheral.
The prvUSCI_A2_ISR() in mspUart.c fires when bytes are received on the MSP430 UART. The bytes are placed into the circular buffer and a notification is posted to the uartProcessor task. The uartProcessor will start the UartProcessorRxStateMachine() when the notification is received to process any bytes in the circular buffer. The UART RX state machine works via function pointers. The RX state machine will follow these steps to frame a JSON-RPC message from the bytes available in the circular buffer:
- UartProcessor_lookForStartByte
- UartProcessor_validateHeader
- UartProcessor_validateTrailer
- UartProcessor_parseMsg
Once a complete message is validated in the UartProcessor_parseMsg() function, the corresponding API function can be called via function pointers provided in the auto generated code. For example, once a Query Firmware Version Response is received the QueryFirmwareVersionIn function can be called.
Again, functions in the JSON library are included in the auto-generated code to extract the relevant data from the JSON-RPC Serial-to-BLE API message. Application specific code can be added between the App Code Start and End comments to perform useful operations on the data received.
This video shows how to facilitate Low Power Mode (LPM) settings using commands in the Serial-to-BLE software API. The video walks through several scenarios using the Serial-to-BLE scripting tool with the help of a logic analyzer. (11:06)
This video walks through the steps to check the status of the battery powering SaBLE-x by utilizing the 'Query Module Sensors Request' and 'Query Module Sensors Response' commands in the Serial-to-BLE API. (1:36)
The ST Nucleo-L152RE and Texas Instruments MSP-EXP430F5438 SaBLE-x Host demos both use FreeRTOS. They were both based off the demos provided by FreeRTOS.org.
Both demos incorporate low power management.
At its core, there are four components: An application task, UART processor Task, UART driver, and JSON library. Both demos rely on queues and notifications so tasks and processes can communicate with each other.
The application task is responsible for setting up the SaBLE-x peripheral, deciding what to do with received over the air data, orchestrating over the air transmissions, and telling the system when it is okay to enter low power mode.
The UART processor task is responsible for framing and parsing valid JSON messages. This includes stripping off the message's CRC_CCITT 16 and verifying it against the message. It is also responsible for packing outgoing messages with a CRC-CCITT 16.
The UART driver is responsible for setting up the UART upon boot, disabling the UART for low power mode, and re-enabling the UART upon wakeup. It also notifies the UART processor when bytes have been received so it can begin processing them. Lastly, it allows the UART processor to pass off outgoing messages for transmission.
The JSON library is used to pack and unpack JSON messages. For incoming messages the UART processor calls into this library to decipher the data. After the data is unpacked an event is added to the application task with the applicable data. For outgoing messages, generally propagated by the application task, this library is called to pack the data. Once the data is packed and converted to a string, this library will call into the UART processor to add the CRC-CCITT 16 to the message.
MSP-EXP430F5438 Host Example
- MSP-EXP430F5438A Experimenter Board (1)
- SaBLE-x Dev Board TI Adapter (1)
- SaBLE-x Dev Board (2)>
- MSP-FET430UIF Debug Interface (1)
- IAR Embedded Workbench for MSP430 6.30.2
ST Micro Nucleo-L152RE Host Example
- Nucleo-L152RE (1)
- SaBLE-x Dev Board Arduino Adapter (1)
- SaBLE-x Dev Board (2)
- IAR Embedded Workbench for ARM 7.40.3.8938
Project for TI MSP430F5438 Experimenter Board Host Example
Note: The TI MSP430F5438 Experimenter board uses IAR v.6.30.2 for MSP430.
Select the power input on the MSP-EXP430F5438 to be FET POWER
Place the adapter block on the MSP-EXP430F5438 RF3. Make sure the square pad is on pin 1
Place the TI EM Adapter on the MSP-EXP430F5438
Ensure that the switch states of the development board loaded with the Simple Hosted Peripheral are in the following states (red indicates on)
Place the Peripheral SaBLE-x development board loaded on the TI EM Adapter
Attach the MSP-FET430UIF to the MSP-EXP430F5438
Open the project in IAR and select "Download and Debug"
Click go and the demo will start running
The host code will now be running on the MSP430. All development board LEDs are configured to as follows:
- Any valid UART message received or transmitted will generate a red LED pulse
- The heartbeat LED (green) will pulse every 3 seconds
- On boot the device will be advertising; the advertising LED (blue) will pulse every second.
After clicking go you should see the red LED on the SaBLE-x Development Board pulse a few times, then once the host is done configuring the heartbeat LED and advertising LED should be pulsing.
Connect the other SaBLE-x development board to the PC and connect to it with the Developer Tool Suite
Select the COM port and Click OK
Scan for the other advertising SaBLE-x development board
Connect to the advertising SaBLE-x development board
Wait for the Developer Tool Suite to come back with a Link Status of "1"
The MSP-EXP430F5438 will now indicate via the LCD that it is connected
Press the joystick on the MSP-EXP430F5438 multiple times
On the Developer Tool Suite you will see inbound over the air messages alternate between sending light, temperature, and tilt data from the SaBLE-x Development Board's sensors
Furthermore, the MSP-EXP430F5438's LCD will indicate the write was successful or not
Now using the Developer Tool Suite send ASCII data to the peripheral
The MSP-EXP430F5438 will now display the data it received
Now using the Developer Tool Suite send HEX data to the peripheral
The MSP-EXP430F5438 will now display the data it received
Project for ST Nucleo-L152RE Board Host Example
Note: The ST Nucleo-L152RE board uses IAR v.7.40.3 for ARM.
Place the Arduino Adapter on the Nucleo-L152RE
Ensure that the switch states of the development board loaded with the Simple Hosted Peripheral are in the following states (red indicates on)
Place the Peripheral SaBLE-x Development Board on the Arduino Adapter
Open the project in IAR and select "Download and Debug"
Click go and the demo will start running
The host code will now be running on the Nucleo-L152RE. All development board LEDs are configured to as follows:
- Any valid UART message received or transmitted will generate a red LED pulse
- The heartbeat LED (green) will pulse every 3 seconds
- On boot the device will be advertising; the advertising LED (blue) will pulse every second.
After clicking go you should see the red LED on the SaBLE-x Development Board pulse a few times, then once the host is done configuring the heartbeat LED and advertising LED should be pulsing.
Connect the other SaBLE-x development board to the PC and connect to it with the Developer Tool Suite
Select the COM port and Click OK
Scan for the other advertising SaBLE-x development board
Connect to the advertising SaBLE-x development board
Wait for the Developer Tool Suite to come back with a Link Status of "1"
Once connected we can query the peripheral SaBLE-x Development board's sensors by sending over the air ASCII commands from the central. The following commands are supported
- light
- temp
- tilt
Send the "light" command
Reception of Light Data in LUX
Send the "temp" command
Reception of Light Data in C
Send the "tilt" command
Reception of Tilt Data; refer to the API for definition of bitmask
This video explores the convenient BLE Configuration tool added to the DTS, which allows you to calculate the battery life of your BLE application based on a straight-forward worksheet of parameters. This tool then also determines your ideal connection parameters and the settings to utilize when implementing Serial-to-BLE to achieve that battery performance. (6:08)
This short video discusses troubleshooting tips for developing with this serial protocol, as well as detailing how to contact the LSR Technical Support team with questions or issues related to Serial-to-BLE. (3:30)