This lab exercise will have you configure/deploy a custom (private) 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.
- Configure a custom “GATT Stopwatch Service” attribute table on a BM71 using the UI Configuration Tool.
- Create a BM71 "Configuration EEPROM table" for inclusion into the PIC24 project.
- Prepare the BM71 PICTail for use on the Explorer16 board.
- Program the PIC24 MCU Stopwatch Demo Project.
- Interact with the Service using the Stopwatch App.
The PIC24 demo code provided in this lab implements the BM71 Configuration EEPROM programming algorithm, simplifying deployment of static/default BM71 parameters in the final application.
After creating a BM71 UI Configuration text file, you will run the BM7x EEPROM Table Utility to convert this file into an EEPROM table array that is #included in the PIC24 MPLAB project.
On reset, the PIC24 demo code reads the configuration memory of the BM71, and if it differs from the table, re-programs all BM71 configuration EEPROM memory contents with the settings in the table.
- BM71 PICtail
- Explorer16 Development Board
- MPLAB® ICD3
- 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
- BM70 Tools
- BLE Stopwatch App (Android)
BEFORE YOU BEGIN:
- Install MPLAB X IDE and XC16 Compiler
- Install the MCP2200 USB driver
- Download the BM7x EEPROM Table Utility using the link above
- Download/extract the UI Configuration Tool as well as the Manual Pattern Test Tool to your PC using the links above
- Download/extract the Explorer16 BM7x Pictail Stopwatch Project to your "C:\" folder
GAP Peripheral Device (GATT Server)
The Explorer16 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/connects to a specific stopwatch. Also can trigger the stopwatch to begin counting.
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.
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.
"Default" BM71 Configuration Files are located in the root folder where the UI Config Tool is installed.
Change the Device Name, UART Setting, Operation Mode
Under System Setup: Device Information, set the Name Fragment to a unique value. This identifier will become the GAP Service "Device Name" characteristic.
Recommend a maximum length of 8 characters.
If your name is longer than 8 chars, you will see an error message when filling in the balance of your ADV_IND payload (remember, we only have 31 bytes of payload!)
Under System Setup: Uart Setting, enable UART RX_IND pin function.
Under System Setup: Operation Mode Setting, set the Operation Pattern to "Manual Pattern" as shown:
Hit “Next” to proceed to the “System Setup2” Tab
Advertising Interval (ADV_IND Packets)
Under LE Mode Setup: LE Advertising Setting, change the default "LE Fast Advertising Interval" to 100mS (0x00A0) as shown:
LE Reduced Power Advertising Interval parameter (not shown above) is only used in Auto Pattern (Transparent UART) mode operation. You do not need to modify this.
BLE "ADV_IND" type advertising packet is a generic advertisement, meaning that it is undirected and is connectable. This would be the initial default advertising type for a new product, before it has paired with a smartphone.
Advertising Payload (ADV_IND Packets)
Under LE Mode Setup: Advertising Data Setting, add the Stopwatch Service UUID (0x8E9598AC066211E6B5123E1D05DEFE78) to the ADV_IND payload as shown:
The Stopwatch App uses the Service UUID form the ADV_IND packets to filter out other devices, only displaying Stopwatch Devices on a scan.
Hit “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 Control Point” Characteristic:
Value:0x00 (1 byte)
Value Permissions: Write/Write without response
“Stopwatch Status” Characteristic:
Value:0x0000000000 (5 bytes)
Value Permissions: Read/Notify
Requires Client Characteristic Configuration Descriptor (CCCD) (UUID: 0x2902) with value 0x0000
- These UUIDs are "version 1" types, and were generated using www.uuidgenerator.net
- Attribute handle values will be automatically assigned by the UI Configuration Tool, starting at 0x8000
- The characteristics need to be added to the service table in the order shown below, so the handle values match those embedded in the PIC24 demo code.
Create Custom GATT Service Table
Scroll down to the "Add-on Service" section, 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:
Hit “Next” to enter the first characteristic.
Add "Stopwatch Status" Characteristic
In the “Add-On Service Table” window, 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:
Add CCCD Descriptor Attribute to "Stopwatch Status" Characteristic
In the “Add-On Service Table” window, 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 Client Characteristic Configuration Descriptor (CCCD) by entering its Hex UUID value (0x2902) and initial value of 0x0000 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.
Prepare the BM71 PICTail for use on the Explorer16 board
Prepare BM71 PICTail Jumpers
Disconnect the USB cable from the PICTail. Configure the module for Application mode by moving dip-switch SW7 to the OFF position. Prepare for connection to Explorer16 by disconnecting the BM71 UART pins from the MCP2200 (remove J3 Jumpers), and finally, set the power source to PIC (Jumper J1) as shown:
Program/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
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).
On 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 “Initiallize Error” - this results upon the host MCU not receiving any response to Read Information command, or an invalid BM71 fw version is read (not v1.06)
- 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 thru 15. Re-create the BM71 EEPROM Configuration Table.
- Alternatively, create/deploy the BM71 EEPROM Configuration Table using the Solution BM71 UI Configuration Fileprovided.
To verify basic functionality of the module, you can revert the PICTail jumpers J3, J1 for standalone operation (as shown) and use the Manual Pattern Test Tool.
Note: You may need to Jumper UART_RX_IND to GND before the tool will be able to communicate as shown here.
Interact With The Service using the Stopwatch App
You will need to research the specific details for installation of .apk application files on your Android device.
Generally, you connect your phone to the PC using the USB cable that came with it, then transfer the .apk file over to the device. Next, go to the "Security" settings, and enable installation of Apps from "sources other than the Play Store". Finally, simply locate and tap on the .apk file to install it.
After installing the app, go to security settings and disable "installation of Apps from sources other than the Play Store"
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 Explorer16 LCD should indicate connected status. In addition, you should see Explorer16 LED_D3 latch to an ON-state indicating a connected state:
Demo Not Working?
Device is connected, however, you cannot start the stopwatch from the app, or you do not receive any updates from the Explorer16 when pressing S3/S6 buttons
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. Here 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):
- 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.
Table of Contents