Chapter 4. Using RN4870 Firmware on BM-70-CDB
4.1 INTRODUCTION
The BM70 module on the BM-70-CDB can be loaded with the RN4870 firmware and operated as an RN4870 module for evaluation and development. Please refer to Appendix A. “Loading RN4870 Firmware”, for the procedure to load the RN4870 firmware onto the BM70 module. Since the BM70 module is programmed with RN4870 firmware, it will be referred to as RN4870 in this section. But when referring to the hardware board, the name BM-70-CDB will be used.
The simplest method to access the BM-70-CDB is to connect it to a PC host that supports USB CDC virtual COM ports. To interact directly with the BM-70-CDB, the following software is needed:
- PC Host supporting USB CDC virtual serial port
- The BM-70-CDB uses the MCP2200 USB to UART bridge. The drivers can be downloaded from www.microchip.com/MCP2200.
- Terminal Emulator Application
- Tera Term or CoolTerm is recommended
- Microchip SmartDiscover App for iOS or Android
- Available on App Store (for iOS) or Google Play Store (Android)
- RN4870 Sensor Board Support Package (RN4870-Sensor-Board-Support.zip)
- This is a collection of files and utilities to assist in configuring the Sensor Board. The files can be downloaded from the www.microchip.com/RN4870 product page.
4.2 CONNECTING THE BM-70-CDB TO A HOST PC
To connect the BM-70-CDB to a host PC, perform the following steps:
1
Configure the BM-70-CDB as follows:
- Pins 2 and 3 on J6 are closed to select USB power option
- J8 is closed
- Operating mode switch ( Switch 2 on SW2) is in position 2 to enable Application mode
- Switch 3 on SW2 is in position 3 to enable LD2 (Blue LED)
2
Connect the BM-70-CDB to the host PC using micro USB cable. Perform the following steps:
- Verify that the virtual COM port is enumerated on the host PC. If the COM port does not enumerate, the MCP2200 drivers may be missing from the host PC. The drivers can be downloaded from the www.microchip.com/MCP2200 web page.
- Press Reset button (SW1) and verify that LD2 is flashing slowly
3
Start the Terminal Emulator software. In this example, Tera Term is used. Configure the enumerated COM port as shown in Figure 4-1.
4
Enter Command mode by sending the command escape sequence $. Pressing the dollar sign ($) three times puts the RN4870 into Command mode and CMD> prompt is displayed. Enable the 'local echo' feature by pressing +, which echoes the character entered by the user on the serial emulator window. The ECHO ON response is displayed as shown in Figure 4-2.
5
To display the basic configuration settings, press the letter <D> followed by <Enter> key (\r), as shown in Figure 4-3. Refer to the “RN4870 Bluetooth® Low Energy Module User's Guide” (DS50002466) for a detailed explanation of the commands.
6
The SmartDiscover App from Microchip can be used to demonstrate RN4870 features. See Figure 4-4 for an example of SmartDiscover App icon. The iOS version of the SmartDiscover App is referred in this document.
7
Once the SmartDiscover App is opened on your smartphone, it discovers the RN4870 peripherals as shown in Figure 4-5.
4.3 CHANGING SETTINGS USING ASCII COMMANDS
The RN4870 firmware is shipped with a default configuration which includes two services (Transparent UART service and Device Info Service) as noted by the result of the previous command D (displays basic configuration). The list of services is indicated as Services = C0. Refer to the “RN4870 Bluetooth® Low Energy Module User's Guide” (DS50002466) for a bitmap of services. The RN4870 can be discovered using the Bluetooth SmartDiscover App. The SmartDiscover App is available in the iTunes Store and the Google Play Store.
To enable built-in services and connect to the RN4870, perform the following steps:
1
Connect the BM-70-CDB to the host PC USB port:
- Using Terminal Emulator, open the COM port enumerated for the BM-70-CDB
- Type $ to enter Command mode
- Enter + to turn on ECHO. Refer to Figure 4-2.
2
To change the default name, send the following commands:
- S-,BLE to create a unique serialized name based on Bluetooth (BT) address of the device.
- R,1 to reboot the module and enable the configuration commands to take effect. Refer to Figure 4-6.
3
Verify that the changes made using the S- command are saved by the reboot, with the following steps:
- Type $ to enter Command mode
- Enter + to turn on local echo
- Issue command D to display the settings
- Verify that the name of the device is BLE-b1b0, where b1b0 are the low order bytes of the BT address; in this example, the Bluetooth is set to BLE-B1E4. Refer to Figure 4-7.
4.4 CONNECTING TO THE RN4870 USING SMARTDISCOVER APP
To connect the RN4870 using SmartDiscover App, perform the following steps:
1
Configure the RN4870 according to the steps listed in Section 4.3 “Changing Settings Using ASCII Commands”. Connect it to the host PC and type $ to enter Command mode.
2
Launch the SmartDiscover App. Refer to Figure 4-8 for how to demonstrate the SmartDiscover App on an iOS device.
3
Verify that the RN4870 device name, BLE-b1b0, is displayed. In this example, the device name is BLE-B1E4 as shown in Figure 4-8.
4
Click the RN4870 device from the list to initiate a connection.
5
Ensure that the connection is established. The GATT service view is illustrated in Figure 4-9. The connection is also verified by the %CONNECT,1,<MAC> status message returned by the RN4870/71 UART. The <MAC> is the address of the remote BT device that initiated the connection. The response in the terminal emulator is shown in Figure 4-10.
4.5 CREATING CUSTOM GATT SERVICES
The RN4870 module supports custom (or private) GATT services. Public GATT services are defined by specifications published by the Bluetooth Special Interest Group (SIG). Private GATT services are defined by the user to host information stored in the GATT characteristics. For more information on GATT services, refer to Appendix E. “Bluetooth Low Energy Primer”.
To create a private GATT service, enter the configuration commands listed in Step 3 below. The commands can be entered as shown in this user guide, or copied from configuration files and pasted into the terminal emulator. The configuration text files are included in the RN4870 Sensor Board Support package that can be downloaded from the product web page at www.microchip.com/RN4870.
1
Connect the BM-70-CDB to the host PC USB port
- Using a terminal emulator, open the COM port to the RN4870
- Type $ to enter Command mode
- Enter + to turn on ECHO.
2
Set Factory Default values
- Enter PZ to clear all services and characteristics
- Enter SF,1
- Verify that the module reboots after the command is entered.
3
Create the private GATT service with three characteristics by entering the following commands:
PS,4D6963726F636869702D524E34383730
PC,BF3FBD80063F11E59E690002A5D5C501,02,02
PC,BF3FBD80063F11E59E690002A5D5C502,02,02
PC,BF3FBD80063F11E59E690002A5D5C503,18,04
These commands can be entered manually by typing each line followed by the <Enter> key from the file 3.4-GATT-service.txt, or each line copied and pasted one by one into the terminal emulator.
Command PS creates the GATT service, identified by the 16-byte private UUID: 4D6963726F636869702D524E34383730. This command must be called before command PC.
Command PC creates the private characteristics. Each characteristic is identified by the following UUIDs:
BF3FBD80063F11E59E690002A5D5C501
,
BF3FBD80063F11E59E690002A5D5C502
,
BF3FBD80063F11E59E690002A5D5C503
.
Command PC expects three parameters. The first parameter is the UUID, the second parameter is the characteristic property (refer to Table E-1 in Appendix E. “Bluetooth Low Energy Primer”), and the third parameter is the size of the data of the characteristic.
4
Reboot the module using command R,1 to ensure that the new GATT service takes effect.
5
Verify that the GATT service is correctly configured.
- Enter Command mode ($) after rebooting the module.
- Issue the LS command to list the GATT server services and their characteristics. The response is illustrated in Figure 4-11.
6
The result of the command LS is shown in Figure 4-11. A custom GATT service (UUID: 4D6963726F636869702D524E34383730) with three characteristics identified by low-order bytes C501, C502 and C503 from the 128-bit UUID. A 16-bit handle is assigned to each characteristic. Handles are used to reference and identify 128-bit characteristic UUIDs more efficiently in the GATT service. Note that there are two references for C503 characteristic. In the first case, in reference 0076, the property value 08 has the write property enabled (refer to Table E-1 in Appendix E. “Bluetooth Low Energy Primer”). Likewise, reference 0077 has the notification property 10 enabled. This means that to write a value to characteristic C503, reference 0076 is used. To enable Client notifications on this characteristic, reference 0077 is used.
4.6 ACCESSING GATT SERVICE USING UART COMMANDS AND SMARTDISCOVER APP
The following examples show how to read and write GATT characteristic values by using UART commands:
1
To write a value to the GATT Server characteristic C501, use the Server Handle Write (SHW) command with handle (for example, 0072) as the first parameter, following by hex-byte values as shown in Figure 4-12.
2
To read a value from the GATT Server characteristic C501, use the Server Handle Read (SHR) command with handle (for example, 0072) as first parameter, following by hex-byte values as shown in Figure 4-12.
3
It is also possible to access the GATT server over a Bluetooth Low Energy connection using the SmartDiscover App. Launch the SmartDiscover App and connect to the RN4870 configured with the private GATT as shown in Section 4.5 “Creating Custom GATT Services”. In this example, the device “BLE-B1E4” is used. Follow the steps in Figure 4-13 to read the value of the GATT characteristic C501. In Step 1, click on the name of your device (BLE-B1E4 >), in Step 2 click on the UUID (BF3FBD80063F11E59E690002A5D5C501 >) and in Step 3 click on Read. The characteristic value is read from the RN4870 into the Smart Discover App.