4.1.2.9 BLE Multiple Advertising Sets
Getting Started with Peripheral Building Blocks
Introduction
This document will help users to enable BLE Multiple Advertising Sets on WBZ351 Curiosity board using MPLAB Code Configurator(MCC) In this application example 2 set of advertisements are implemented. For details on this feature, refer to Section "4.4.2.10 Advertising Sets", BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 6, Part B.
Users of this document can choose to just run the precompiled Application Example hex file on the WBZ351 Curiosity Board and experience the demo or can go through the steps involved in developing this Application from scratch
These examples each build on top on one and other. We strongly recommend that you follow the examples in order, to learn the basics concepts before progressing to the more advanced topics.
Recommended Reading
Hardware Requirement
Tool | Qty |
---|---|
WBZ351 Curiosity Board | 1 |
Micro USB cable | 1 |
SDK Setup
Gettting Started with Software DevelopmentSoftware Requirement
TeraTermSmartphone App
Light BlueProgramming the Precompiled hex file or Application Example
Programming the hex file using MPLABX IPE
-
Precompiled Hex file is located in "
<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\two_set_adv\hex"
folder -
For more details on the steps, go to Programming A Device .Note: Ensure to choose the correct Device and Tool information
Programming the Application using MPLABX IDE
-
Follow steps mentioned in of Running a Precompiled Example document
-
Open and program the Application Example "two_set_adv.X" located in
"<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\two_set_adv\firmware"
using MPLABX IDE
For more details on how to find the Harmony Content Path, refer to Installing the MCC Pluggin
Demo Description
- One is connectable and the other is non Connectable. On reset this demo will print "2 Set Advertising..." on a terminal emulator like TeraTerm. This denotes the start of advertisements.
Testing
Developing the Application from Scratch using MPLAB Code Configurator
-
Create a new MCC Harmony Project. For more details, refer to Creating a New MCC Harmony Project .
-
Import component configuration: This step helps users setup the basic components and configuration required to develop this application. The imported file is of format .mc3 and is located in the path
"<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\two_set_adv\firmware\two_set_adv.X".
Users must follow the instructions mentioned 13.3 Importing Existing App Example Configuration to import the component configuration. -
Accept Dependencies or satisfiers, select "Yes"
-
Verify if the Project Graph window has all the expected configuration.
Verifying Advertisement
-
Select BLE_Stack component in project graph
- Advertising Set1
- Advertising Set2
Generating a Code
For more details on code generation, refer to 13.2 MPLAB Code Configurator(MCC) Code Generation.
Files and Routines Automatically generated by the MCC
After generating the program source from MCC interface by clicking Generate Code, the BLE configuration can be found in the following project directories
The OSAL, RF System, BLE System initialization routine executed during program initialization can be found in the project files. This initialization routine is automatically generated by the MCC
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.c | Source Code for the BLE stack related component configurations, code related to function calls from app.c |
app_ble_handler.c | All GAP, GATT, SMP and L2CAP Event handlers |
Header Files
-
ble_gap.h:
This header file contains BLE GAP functions and is automatically included in the app.c file
Function Calls
MCC generates and adds the code to initialize the BLE Stack GAP, GATT, L2CAP and SMP in APP_BleStackInit() function
-
APP_BleStackInit() is the API that will be called inside the Applications Initial State -- APP_STATE_INIT in app.c
User Application Development
Include
-
User action is required as mentioned User Action
-
definitions.h
in all the files where UART will be used to print debug information
definitions.h
is not specific to just UART
peripheral, instead it should be included in all application source files where
peripheral functionality will be exercisedConfigure 2 set of Advertisements
-
APP_BleConfigAdvance( );
The following code snippet is to configure the advertising Set 1:
//Configure advertising Set 1
advParams.advHandle = 1; /* Advertising Handle */
advParams.evtProperies = BLE_GAP_EXT_ADV_EVT_PROP_CONNECTABLE_ADV|BLE_GAP_EXT_ADV_EVT_PROP_SCANNABLE_ADV|BLE_GAP_EXT_ADV_EVT_PROP_LEGACY_ADV; /* Advertising Event Properties */
advParams.priIntervalMin = 32; /* Primary Advertising Interval Min */
advParams.priIntervalMax = 32; /* Primary Advertising Interval Max */
advParams.priChannelMap = BLE_GAP_ADV_CHANNEL_ALL; /* Primary Advertising Channel Map */
memset(&advParams.peerAddr, 0x00, sizeof(advParams.peerAddr));
advParams.filterPolicy = BLE_GAP_ADV_FILTER_DEFAULT; /* Advertising Filter Policy */
advParams.txPower = 9; /* Advertising TX Power */
advParams.priPhy = BLE_GAP_PHY_TYPE_LE_1M; /* Primary Advertising PHY */
advParams.secMaxSkip = 0; /* Secondary Advertising Max Skip */
advParams.secPhy = BLE_GAP_PHY_TYPE_LE_1M; /* Secondary Advertising PHY */
advParams.sid = 1; /* Advertising SID */
advParams.scanReqNotifiEnable = false; /* Scan Request Notification Enable */
BLE_GAP_SetExtAdvParams(&advParams, &selectedTxPower);
appAdvData.advHandle = 1;
appAdvData.operation = BLE_GAP_EXT_ADV_DATA_OP_COMPLETE;
appAdvData.fragPreference = BLE_GAP_EXT_ADV_DATA_FRAG_PREF_ALL;
appAdvData.advLen = sizeof(advData);
appAdvData.p_advData=OSAL_Malloc(appAdvData.advLen);
if(appAdvData.p_advData)
{
memcpy(appAdvData.p_advData, advData, appAdvData.advLen); /* Advertising Data */
}
BLE_GAP_SetExtAdvData(&appAdvData);
OSAL_Free(appAdvData.p_advData);
The below code snippet is to configure the advertising Set 2:
//Configure advertising Set 2
advParams.advHandle = 2; /* Advertising Handle */
advParams.evtProperies = BLE_GAP_EXT_ADV_EVT_PROP_LEGACY_ADV; /* Advertising Event Properties */
advParams.priIntervalMin = 32; /* Primary Advertising Interval Min */
advParams.priIntervalMax = 32; /* Primary Advertising Interval Max */
advParams.priChannelMap = BLE_GAP_ADV_CHANNEL_ALL; /* Primary Advertising Channel Map */
memset(&advParams.peerAddr, 0x00, sizeof(advParams.peerAddr));
advParams.filterPolicy = BLE_GAP_ADV_FILTER_DEFAULT; /* Advertising Filter Policy */
advParams.txPower = 9; /* Advertising TX Power */
advParams.priPhy = BLE_GAP_PHY_TYPE_LE_1M; /* Primary Advertising PHY */
advParams.secMaxSkip = 0; /* Secondary Advertising Max Skip */
advParams.secPhy = BLE_GAP_PHY_TYPE_LE_1M; /* Secondary Advertising PHY */
advParams.sid = 2; /* Advertising SID */
advParams.scanReqNotifiEnable = false; /* Scan Request Notification Enable */
BLE_GAP_SetExtAdvParams(&advParams, &selectedTxPower2);
appAdvData.advHandle = 2;
appAdvData.operation = BLE_GAP_EXT_ADV_DATA_OP_COMPLETE;
appAdvData.fragPreference = BLE_GAP_EXT_ADV_DATA_FRAG_PREF_ALL;
appAdvData.advLen = sizeof(advData2);
appAdvData.p_advData=OSAL_Malloc(appAdvData.advLen);
if(appAdvData.p_advData)
{
memcpy(appAdvData.p_advData, advData2, appAdvData.advLen); /* Advertising Data */
}
BLE_GAP_SetExtAdvData(&appAdvData);
OSAL_Free(appAdvData.p_advData);
Start Advertisement
- BLE_GAP_SetExtAdvEnable(true, 2, extAdvEnableParam);
This API is called in the Applications initialization - APP_STATE_INIT in app.c
Users can exercise various other BLE Advertisement functionalities by using BLE Stack API