BM71 Stopwatch Demo (Private Service)
Objective
This lab exercise will have you configure/deploy a custom (private) Generic Attribute Profile (GATT) Service (Stopwatch Service) on a BM71, then interface it with a PIC24 MCU (running demo code) and test it using a dedicated Android Stopwatch App.
You will:
- Configure a custom “GATT Stopwatch Service” attribute table on a BM71 using the User Interface (UI) Configuration Tool.
- Create a BM71 "Configuration EEPROM table" for inclusion into the PIC24 project.
- Prepare the BM71 PICTail for use on the Explorer 16 board.
- Program the PIC24 MCU Stopwatch Demo Project.
- Interact with the Service using the Stopwatch App.
Reference Materials
- BM71 PICtail™
- Explorer 16 Development Board
- MPLAB ICD 3 In-Circuit Debugger
- Android Smartphone (Lab tested with BLU Advance 5.0)
- OS version 4.4 or higher
- BT 4.0 or higher hardware
- MPLAB X IDE
- MPLAB XC16 Compiler
- MCP2200 USB Driver
- User Interface (UI) Configuration Tool
- Manual Pattern Test Tool
Connection Diagram
Overview
Generic Access Profile (GAP) Peripheral Device (GATT Server)
The Explorer 16 Board with the BM71 advertises a Stopwatch Service, which provides stopwatch data to a smartphone, as well as providing a control point to remotely trigger the stopwatch to start counting.
GAP Central Device (GATT Client)
An Android smartphone running the Stopwatch demo app, scans, filters, and connects to a specific stopwatch. It also can trigger the stopwatch to begin counting.
Procedure
GATT Server Configuration
In this sequence, you will configure the BM71 static parameters for this application, including creating the GATT Table for the Stopwatch Service.
Verify Module Firmware Version
This demo requires BM71 module firmware version 1.06. Verify the firmware version, and if necessary, program v1.06 firmware into the module.
Load UI Configuration
Launch the UI Configuration Tool (found in the "Software Tools" section above) and load in the Default BM71 UI Config File (IS1871SF_102_BLEDK3_UI v100.132(BM71) default.txt), which you obtained from the "Exercise Files" section of this page.
Edit UI Configuration
Select Edit and ensure that the BLEDK radio button is checked and that BM71 is the device selected under the Main Feature window. Then press OK.
Change the Device Name, UART Setting, Operation Mode
On the System Setup tab, in the Device Information pane, set the Name Fragment to a unique value. This identifier will become the GAP Service Device Name characteristic.
On the System Setup tab, in the Uart Setting pane, select Enable for UART RX_IND pin function.
In the Operation Mode Setting pane, set the Operation Pattern to Manual Pattern as shown:
Click Next to proceed to the System Setup2 Tab
GPIO Configuration
On the System Setup2 tab, in the GPIO Configuration pane, select NO_USE for all pin functions EXCEPT P16, which should be assigned to the UART_RX_IND function as shown:
Click Next to proceed to the LE Mode Setup tab.
Advertising Interval (ADV_IND Packets)
On the LE Mode Setup tab, in the LE Advertising Setting pane, change the default LE Fast Advertising Interval to 100 mS (0x00A0). Enter 00A0 as shown:
Advertising Payload (ADV_IND Packets)
On the LE Mode Setup tab, in the Advertising Data Setting pane, add the Stopwatch Service UUID (0x8E9598AC066211E6B5123E1D05DEFE78) to the ADV_IND payload as shown:
Click Next to proceed to the GATT Service Table tab.
GATT Stopwatch Service
You will now create the Stopwatch Service attribute table having the following characteristics and features:
Stopwatch Service:
UUID: 0x8E9598AC066211E6B5123E1D05DEFE78
Stopwatch Control Point Characteristic:
UUID: 0x8E959DE8066211E6B5123E1D05DEFE78
Value:0x00 (1 byte)
Value Permissions: Write/Write without response
Stopwatch Status Characteristic:
UUID: 0x8E959FE6066211E6B5123E1D05DEFE78
Value:0x0000000000 (5 bytes)
Value Permissions: Read/Notify
Requires Client Characteristic Configuration Descriptor (CCCD) (UUID: 0x2902) with value 0x0000
Create Custom GATT Service Table
Scroll down to the Add-on Service pane, and from the Service List, drag/drop Others into the Add-on Service Table view as shown:
You should see a dialog box prompting you to define a new private service. Type/Copy/Paste the Stopwatch Service UUID value (0x8E9598AC066211E6B5123E1D05DEFE78) into the UUID field as shown:
Click Next to enter the first characteristic.
Add "Stopwatch Control Point" Characteristic
Enter the Hex UUID value (0x8E959DE8066211E6B5123E1D05DEFE78), Permissions (Properties), and initial Characteristic Value for the Stopwatch Control Point characteristic (defined above), as shown:
Click OK.
Add Stopwatch Status Characteristic
Under Add-On Service Table, add the next characteristic by right-clicking on the Service UUID and selecting Add Characteristic as shown:
Enter the Hex UUID value (0x8E959FE6066211E6B5123E1D05DEFE78), Permissions (Properties), and Characteristic Value (0x0000000000) for the Stopwatch Status characteristic (defined above), as shown:
Click OK.
Add Client Characteristic Configuration Descriptor (CCCD) Attribute to Stopwatch Status Characteristic
Under Add-On Service Table, expand all the + tabs to see the completed GATT Service Table. Right-click on the characteristic handle 0x8003. We need to add a descriptor attribute (CCCD, type 0x2902) to this characteristic:
Define a CCCD by entering its Hex UUID value (0x2902) and initial value of 0x0000 as shown:
Click OK.
Review GATT Service Table
In the Add-On Service Table pane, expand all the + tabs to see the completed GATT Service Table. It should match as shown:
Click Next to proceed to the LED Setup tab.
LED0 Setup
On the LED Setup tab, configure P0_2/LED0 output to flash two times per second during advertising (Standby mode), and then turn fully on when a connection is established, as shown:
Click Finish.
Save BM71 Configuration Settings to a File
Click Save to save your settings to a BM71 configuration file (for example C:\Masters\20055\Lab4\bm71-config\bm71-config.txt) as shown :
Click OK to close the final dialog box.
Close UI Config Tool
Close the UI Configuration Tool as shown:
Create BM71 Config EEPROM Table Array
The PIC24 demonstration code simplifies deployment of BM71 configuration settings by in-circuit-programming the module's configuration EEPROM memory. In this next sequence, you will convert your BM71 configuration file into a Flash Configuration Table that can be #included in the MPLAB project.
Start the BM7x EEPROM Utility, Load the BM71 Configuration File
Launch the BM7x EEPROM Table Utility (found in the "Software Tools" section above). When prompted, navigate to your saved configuration file from Step 14 above:
Create the BM71 Configuration EEPROM Table in the MPLAB Project Folder
When prompted, save the output file to the PIC24 demo project folder C:\host-firmware\Explorer16 BM70 Pictail Stopwatch.X.
Prepare the BM71 PICTail for use on the Explorer 16 board
Prepare BM71 PICTail Jumpers
Disconnect the USB cable from the PICTail board. Configure the module for Application mode by moving dip-switch SW7 to the OFF position. Prepare for connection to Explorer 16 by disconnecting the BM71 UART pins from the MCP2200 (remove J3 Jumpers), and finally, set the power source to PIC (Jumper J1) as shown:
Install BM71 PICTail
Install the BM71 PICTail into the Explorer 16 board as shown (Ensure PIC24FJ128GA010 PIM is installed):
Program and Run the PIC24 MCU Stopwatch Demo Project
Open the Project
Start MPLAB X and open the project C:\host-firmware\Explorer16 BM70 Pictail Stopwatch.X.
Select the BM71 Project Configuration
Select the BM71 project configuration as shown:
#include the BM71 Configuration EEPROM Table
Open with your editor the file bm70_configure.c. Go to line 57 and change the name of the #included BM71 EEPROM Table file to the name you chose in Step 17:
Build/Run the Project
Build/Run the project by pressing the Make and Program Device button.
You will first see “Initializing…” text on the LCD display, indicating the initialization of the BM71 parameters, as well as verification of correct BM71 firmware version (1.06).
Upon success, the LCD should display the device name, the last four bytes of the MAC address, as well as a stopwatch display.
LED_D3 should also blip two times per second indicating an advertising state.
PIC24 Demo Startup Troubleshooting
LCD reads “Initialize Error"
This results in the host MCU not receiving any response to Read Information command, or an invalid BM71 fw version is read (not v1.06).
Possible Causes:
- Incorrect PICTail jumper settings—review Step 18.
- Incorrect BM71 firmware—reprogram with v1.06.
- Incorrect BM71 configuration—re-load your saved BM71 UI configuration file and verify correct settings as described in steps 1 through 15. Re-create the BM71 EEPROM Configuration Table.
- Alternatively, create/deploy the BM71 EEPROM Configuration Table using the provided.
Sanity Check:
To verify the basic functionality of the module, you can revert the PICTail jumpers J3 and J1 for standalone operation (as shown) and use the Manual Pattern Test Tool.
Interact With The Service using the Stopwatch App
Start The App, Scan for Stopwatch Devices, Select Device
Start the Stopwatch App on your smartphone:
Tap on SCAN to begin scanning for devices as shown:
Locate and Tap on your device to establish a connection to it. The Explorer 16 LCD should indicate connected status. In addition, you should see Explorer 16 LED_D3 latch to an ON-state indicating a connected state:
Interact With The Service
Once connected, you will be taken to the main activity page for the app.
Press Start to start the stopwatch from the App.
Press Explorer 16 switch S3 to start/stop the display. Press S6 to Reset.
The History window will show track these events as shown:
Demo Not Working?
Symptoms:
The device is connected, however, you cannot start the stopwatch from the app, or you do not receive any updates from the Explorer 16 when pressing S3/S6 buttons.
Causes:
The most likely cause is a mismatch between the characteristic handle values in the BM71 GATT Service Table, vs what is encoded in the PIC24 firmware.
In MPLAB X IDE, open file definitions.h, and scroll to line 106. This is where we define the Handle IDs for each characteristic we want to update in our application:
In particular, note the two handles circled. The first is the writable characteristic Stopwatch Control Point (0x8002), the second is the notify characteristic Stopwatch Status (0x8004).
The Handle values for these two characteristics need to match those generated by the UI Configuration tool (see Step 12):
Conclusions
- Private GATT Services are easily created on the BM71 using the UI Configuration tool.
- The BM7x EEPROM Table Utility is used to convert a UI Configuration file to an EEPROM Table that can be embedded into your project, simplifying production deployment.
- The MCU Host must capture BLE connection parameters (including Connection Handle) to be able to modify characteristic values in the BM71.
- Care must be taken to embed the correct characteristic handles generated by the tool into the embedded host code.