5.1.2.3 BLE Extended Advertisements
This section explains how to enable Extended Advertisements (1M, 2M, Coded PHY - 125 kbps) on the WBZ351 Curiosity Board. This example enables users to send application data using extended advertisements.
Extended Advertisements are used to send more data than what legacy advertisements allow and also has long range functionality when using Coded PHY. Use of Extended Advertisements also enables the users to select between different PHYs (1M, 2M and LE Coded) which are not permitted when using legacy advertisements. In BLE, a peripheral or broadcaster always starts with advertisements. Advertisement packets enable a central or observer to discover a peripheral or broadcaster.
This example uses Extended Advertisements for either transmitting more data (2M PHY) or conducting range tests (Coded PHY). For testing these features, a scanner application can be used which is configured to scan the extended advertisement packets.
To save power, low power mode can be enabled. If conditions are met, then the WBZ351 will enter into sleep mode. The following sections discuss it in detail.
Users can choose to either run the precompiled Application Example hex file provided on the WBZ351 Curiosity Board or follow the steps to develop the application from scratch.
These examples build upon one another. It is recommended to follow the examples in sequence to understand the basic concepts before progressing to the advanced topics.
Recommended Readings
-
Getting Started with Application Building Blocks – See Building Block Examples from Related Links.
-
Getting Started with Peripheral Building Blocks – See Peripheral Devices from Related Links.
-
FreeRTOS and BLE Stack Setup – See Peripheral - FreeRTOS BLE Stack and App Initialize from Related Links.
-
BLE Software Specification – See MPLAB® Harmony Wireless BLE in Reference Documentation from Related Links.
- See Low Power Design on PIC32CXBZ3 Devices from Related Links.
Hardware Requirement
| S. No. | Tool | Quantity |
|---|---|---|
| 1 | WBZ351 Curiosity Board | 1 (2 if testing with a scanner) |
| 2 | Micro USB cable | 1 |
| 3 | Android/iOS Smartphone | 1 |
| 4 | (Optional) Power
Debugger(1)/Multimeter/Oscilloscope to measure power
Note:
| 1 |
SDK Setup
Refer to Getting Started with Software Development from Related Links.
Software Requirement
To install Tera Term tool, refer to the Tera Term web page in the Reference Documentation from Related Links.
Smartphone App
None
Programming the Precompiled Hex File or Application Example
Using MPLAB® X IPE:
- Import and program the
precompiled hex file:
.<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\ext_adv\hex\ext_adv.X.production.signed.hex - For detailed steps, refer to
Programming a Device in MPLAB® IPE in
Reference Documentation from Related Links.Note: Ensure to choose the correct Device and Tool information.
Using MPLAB® X IDE:
- Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.
- Open and program the application:
<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\ ext_adv\firmware\ext_adv.X. - For more details on how to find the Discover path, refer to Download Application Example from Discover in Running a Precompiled Application Example from Related Links.
Demo Description
- Application data ("Microchip") is transmitted in Auxiliary packets (ADV_AUX_IND).
- ADV_EXT_IND carries the Auxiliary Packet Information (ADV_AUX_IND) for the scanner to collect the data.
The message “Ext Adv Enabled” will be printed on Tera Term, indicating successful start of Coded PHY Advertisements. Coded PHY Advertisements are configured to be sent every 2 seconds.
Testing
- Using a micro USB cable, connect the Debug USB on the Curiosity boards to a PC.
- Program the precompiled hex files or application examples:
- Board1: WBZ351 Curiosity Board with BLE Ext Adv Programmed.
- Board2: WBZ351 Curiosity Board with BLE Scan Ext Adv Programmed, see BLE Scanning Extended Advertisements from Related Links.
- Open Tera Term for each
board:
- Set Serial Port to USB Serial Device.
- Set Speed to 115200.
- Reset the boards
- Board 1 will display “Ext Adv Enabled”.
- Board 2 will
display “ExtAdv Scan Enable Success” must be displayed on
TeraTerm. “Microchip” must be displayed as soon the WBZ351 module performs an extended
advertisement scan.
For more details on how to set the “Serial Port” and “Speed”, refer to COM Port Setup in Running a Precompiled Application Example from Related Links.
Current Consumption Measurement
Connect a Multimeter/Power Debugger/Oscilloscope to Power Measurement Header J5. If using a Power Debugger, users can use Data Visualizer to measure the current consumption.
Current measured in sleep/standby mode is 575.6 uA and average current consumption
is around 723.0 uA.
Users of this package should go through the known issues document and understand the limitations, if any, of the current low power mode implementation.
Developing this Application from Scratch using MPLAB Code Configurator
- Setup the Harmony Framework. The EA release package has all the necessary components and should be downloaded individually from the link provided in the package. It is recommended to create the framework in the root directory. This framework looks like:
Create a new harmony project. For more details, see Creating a New MCC Harmony Project from Related Links.
- Setup the basic components and
configuration required to develop this application, import component
configuration:
. For more details on importing the component configuration, refer to Importing Existing App Example Configuration from Related Links.<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\ext_adv\firmware\ext_adv.X\ext_adv.mc4Note: Import and Export functionality of the Harmony component configuration will help users to start from a known working setup of the MCC configuration. - Accept dependencies or satisfiers when prompted.
-
Verify if the Project Graph window has all the expected configuration.
Figure 5-97. Project Graph -
Enable Low Power mode by selecting Low Power Enable in BLE_Stack Configuration and selecting Yes to all pop upsthen click on Window->MCC->Harmony->Clock Configuration and set the following clock configurations.
Verify Advertisement Configuration
- Select the BLE Stack component in the Project Graph.
- Configure Extended Advertisements in the Configuration Options panel as shown in the following image.
Configuring UART
For more details on UART Configuration, refer to csp_apps_pic32cxbz3_wbz3 application examples.
Generating a Code
For more details on code generation, refer to MPLAB Code Configurator (MCC) Code Generation from Related Links.
Files and Routines Automatically Generated by the MCC
Initialization routines for OSAL, RF System, and BLE System are auto-generated by the MCC. See OSAL Libraries Help in Reference Documentation from Related Links.
The BLE stack initialization routine executed during Application Initialization can be found in project files. This initialization routine is automatically generated by the MCC. This call initializes and configures the GAP, GATT, SMP, L2CAP and BLE middleware layers.
Autogenerated Advertisement Data Format
| Source Files | Usage |
|---|---|
app.c | Application State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations |
app_ble\app_ble.c | Source Code for the BLE stack related component configurations, code related to function calls from app.c |
app_ble\app_ble_handler.c | All GAP, GATT, SMP and L2CAP Event handlers |
app_user_edits.c | User Code Change instruction |
app.c is autogenerated and has a state machine-based application
code sample. Users can use this template to develop their own application.Header Files
-
ble_gap.hcontains BLE GAP functions and is automatically included inapp.c
Function Calls
- MCC generates and adds the
code to initialize the BLE Stack GAP, GATT, SMP and L2CAP in
APP_BleStackInit() APP_BleStackInit()is the API that will be called inside the Applications Initial StateAPP_STATE_INITinapp.cRTC_Timer32Start()defined inplib_rtc_timer.ccalls to start the RTC Timer clock to facilitate low power mode
User Application Development
Include
- Include the user action. For more information, refer to User Action from Related Links.
definitions.hmust be included in all the files where UART will be used to print debug information.Note:definitions.his not specific to just UART but instead must be included in all the application source files where any peripheral functionality will be exercised.
Starting Extended Advertisement in app.c
-
BLE_GAP_SetExtAdvEnable(true, 0x01, &extAdvEnableParam);
This API is called in the applications initial state
APP_STATE_INIT in app.c. Parameters
for the extended advertisement must be configured appropriately. The
following image is an example.
Where to go from here
Getting Started with Peripheral Building Blocks – See Peripheral Devices from Related Links.
