BM70 Stopwatch Demo

 Objective

This lab exercise will have you configure/deploy a custom (private) Generic Attribute Profile (GATT) Service (Stopwatch Service) on a BM70, then interface it with a PIC24 MCU (running demo code) and test it using a dedicated Android Stopwatch app.

You will:

The PIC24 demo code provided in this lab implements the BM70 Configuration EEPROM programming algorithm, simplifying the deployment of static/default BM70 parameters.

After creating a BM70 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 BM70, and if it differs from the table, re-programs BM70 configuration EEPROM memory contents with the settings in the table.

 Materials

Hardware Tools

Software Tools

Exercise Files

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 Explorer 16 BM7x PICtail Stopwatch Project to your C:\ folder.

 Connection Diagram

Overview

lab4-connection-diagram.png

Generic Access Profile (GAP) Peripheral Device (GATT Server)

The Explorer 16 Board with the BM70 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.

MCU Interface

lab4-mcu-interface.png

Demo Flowcharts

lab4-flowcharts.png

 Procedure

GATT Server Configuration

In this sequence, you will configure the BM70 static parameters for this application, including creating the GATT Table for the Stopwatch Service.

1

Verify Module Firmware Version

This demo requires BM70 module firmware version 1.06. Verify the firmware version, and if necessary, program v1.06 firmware into the module.

2

Load UI Configuration

Launch the UI Configuration Tool (found in the "Software Tools" section above) and load in the Default BM70 UI Config File (IS1870SF_102_BLEDK3_UI v100.132(BM70) default.txt), which you obtained from the "Exercise Files" section of this page.

NewUILoad.png

3

Edit UI Configuration

Select Edit and ensure the BLEDK3 radio button is checked with BM70 device under Main Feature. Then press OK.

BLEDK3withBM70.png

4

Change the Device Name, Universal Asynchronous Receiver Transmitter (UART) Setting, Operation Mode

In the System Setup tab, under the Device Information pane, set the Name Fragment to a unique value. This identifier will become the GAP Service Device Name characteristic.

Recommend a maximum length of eight characters.

If your name is longer than eight characters, you will see an error message when filling in the balance of your ADV_IND payload. (Remember, we only have 31 bytes of payload!)


In the System Setup tab, under the Uart Setting pane, enable UART RX_IND pin function.

In the System Setup tab, under the Operation Mode Setting pane, set the Operation Pattern to Manual Pattern as shown:

lab4-step4.png

Click Next to proceed to the System Setup2 tab.

5

GPIO Configuration

In the System Setup2 tab, under the GPIO Configuration pane, select NO_USE for all pin functions EXCEPT P33, which should be assigned to the UART_RX_IND function as shown:

lab4-step5.png

Click Next to proceed to the LE Mode Setup tab.

6

Advertising Interval (ADV_IND Packets)

In the LE Mode Setup tab, under the LE Advertising Setting pane, change the default LE Fast Advertising Interval to 100 mS (0x00A0) as shown:

lab4-step6.png

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.

7

Advertising Payload (ADV_IND Packets)

In the LE Mode Setup tab, under the Advertising Data Setting pane, add the Stopwatch Service Universally Unique Identifier (UUID) (0x8E9598AC066211E6B5123E1D05DEFE78) to the ADV_IND payload as shown:

lab4-step7.png

The Stopwatch app uses the Service UUID form the ADV_IND packets to filter out other devices, only displaying Stopwatch Devices on a scan.

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

Notes:

  • These UUIDs are version 1 types and were generated using UUID generator.
  • 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.

8

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:

lab4-step8-1.png

You should see a dialog box prompting you to define a new private service. Type or copy and paste the Stopwatch Service UUID value (0x8E9598AC066211E6B5123E1D05DEFE78) into the UUID field as shown:

lab4-step8-2.png

Click Next to enter the first characteristic.

9

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:

lab4-step9.png

Click OK.

10

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:

lab4-step10-1.png

Enter the Hex UUID value (0x8E959FE6066211E6B5123E1D05DEFE78), Permissions (Properties), and Characteristic Value (0x0000000000) for the Stopwatch Status characteristic (defined above), as shown:

lab4-step10-2.png

Click OK.

11

Add CCCD Descriptor Attribute to Stopwatch Status Characteristic

In the Add-On Service Table pane, 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:

lab4-step11-1.png

Define a CCCD by entering its Hex UUID value (0x2902) and initial value of 0x0000 as shown:

lab4-step11-2.png

Click OK.

12

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:

lab4-step12.png

Click Next to proceed to the LED Setup Tab.

13

LED0 Setup

In the LED Setup pane, 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:

lab4-step13.png

Click Finish.

14

Save BM70 Configuration Settings to a File

Press Save to save your settings to a BM70 configuration file (for example C:\Masters\20055\Lab4\bm70-config\bm70-config.txt) as shown :

lab4-step14.png

Click OK to close the final dialog box.

15

Close UI Config Tool

Close the UI Configuration Tool as shown:

lab4-step15.png

Create BM70 Config EEPROM Table Array

The PIC24 demonstration code simplifies deployment of BM70 configuration settings by in-circuit-programming the module's configuration EEPROM memory. In this sequence, you will convert your BM70 configuration file into a Flash Configuration Table that can be included in the MPLAB project.

If you have not done so already, download and extract the Explorer 16 BM7x PICtail Stopwatch Project to your C:\ folder.

16

Start the BM7x EEPROM Utility, Load the BM70 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:

lab4-step16.png

17

Create the BM70 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.

lab4-step17.png

Prepare the BM70 PICtail for use on the Explorer 16 Board

18

Prepare BM70 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 BM70 UART pins from the MCP2200 (remove J3 jumpers), and finally, set the power source to PIC® (jumper J1) as shown:

lab4-step18.png

19

Install BM70 PICtail

Install the BM70 PICtail board into the Explorer 16 board as shown (ensure PIC24FJ128GA010 PIM is installed):

lab4-step19.png

Program/Run the PIC24 MCU Stopwatch Demo Project

If not done so already, download and extract the Explorer 16 BM7x PICtail Stopwatch Project to your C:\ folder

20

Open the Project

Start MPLAB X and open the project C:\host-firmware\Explorer16 BM70 Pictail Stopwatch.X

21

Select the BM70 Project Configuration

Select the BM70 project configuration as shown:

lab4-step21.png

22

#include the BM70 Configuration EEPROM Table

With your editor, open the bm70_configure.c file. Go to line 57 and change the name of the included BM70 EEPROM Table file to the name you chose in Step 17:

lab4-step22.png

23

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 BM70 parameters, as well as verification of correct BM70 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.

lab4-step23-1.png

LED_D3 should also blip two times per second indicating an advertising state.

lab4-step23-2.png

PIC24 Demo Startup Troubleshooting

LCD reads “Initialize Error"

This results upon the host MCU not receiving any response to Read Information command, or an invalid BM70 fw version is read (not v1.06)

Possible Causes:

  • Incorrect PICtail jumper settings: review Step 18.
  • Incorrect BM70 firmware: reprogram with v1.06.
  • Incorrect BM70 configuration: re-load your saved BM70 UI configuration file and verify correct settings as described in steps 1 through 15. Re-create the BM70 EEPROM Configuration Table.

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 PatternTest Tool. Note, you may need to jumper UART_RX_IND to GND before the tool will be able to communicate as shown:

lab4-troubleshooting.png

Interact With The Service using the Stopwatch App

You will need to research the specific details for the 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 the 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 the "installation of apps from sources other than the Play Store."

24

Start The App, Scan for Stopwatch Devices, and Select Device

Start the Stopwatch App on your smartphone:

lab4-step24-1.png

Tap on SCAN to begin scanning for devices as shown:

lab4-step24-2.png

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:

lab4-step23-2.png

25

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 or Stop the display. Press S6 to Reset.

The History pane will show track these events as shown:

lab4-step25.png

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 handle values in the BM70 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:

lab4-step25-trouble-1.png

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):

lab4-step25-trouble-2.png

 Conclusions

  • Private GATT Services are easily created on the BM70 using the UI Configuration tool.
  • The BM70 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 BM70.
  • Care must be taken to embed the correct characteristic handles generated by the tool into the embedded host code.
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.