5.1.2.9 BLE Multiple Advertising Sets
This section explains how to enable BLE Multiple Advertising Sets on the PIC32-BZ6 Curiosity board using the MPLAB Code Configurator (MCC). In this application example, two sets of advertisements are implemented. For more details, refer to Section “4.4.2.10 Advertising Sets” of BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 6, Part B.
Users can choose to either run the precompiled Application Example hex file provided on the PIC32-BZ6 Curiosity Board or follow the steps to develop the application from scratch.
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.
Hardware Requirement
S. No. | Tool | Quantity |
---|---|---|
1 | PIC32-BZ6 Curiosity Board | 1 |
2 | Micro USB cable | 1 |
3 | Android/iOS smartphone | 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 Reference Documentation from Related Links.
Smartphone App
Light Blue iOS/Android app available in stores
Programming the Precompiled Hex file or Application Example
Using MPLAB® X IPE:
-
Import and program the precompiled hex file:
<Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\building_blocks\peripheral\two_set_adv\precompiled_hex\two_set_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:
<Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\building_blocks\peripheral\ two_set_adv\firmware\two_set_adv.X
. - For more details on how to find the Harmony Content Path, refer to Installing the MCC Plugin from Related Links.
Demo Description
This application transmits two sets of advertisements: one connectable and the other non-connectable. On reset, this demo will print “2 Set Advertising...” in a terminal emulator like Tera Term. This denotes the start of advertisements.
Testing
- Using a micro USB cable, connect the Debug USB on the Curiosity board to a PC.
- Program the precompiled hex file or application example as mentioned.
- Open Tera Term:
- Set the “Serial Port” to USB Serial Device.
- Speed to 115200.
- Press the NMCLR button on the
Curiosity board. “2 Set Advertising...” must be displayed in Tera Term.
- Launch the Light Blue mobile
app to scan for Advertisements. Device names “PIC32WM_BZ6204_1” and
“PIC32WM_BZ6204_2” should appear.
Developing the Application from Scratch using MPLAB Code Configurator
- Create a new harmony project. For more details, see Creating a New MCC Harmony Project from Related Links.
-
To setup the basic components and configuration required to develop this application, import component configuration:
<Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\building_blocks\peripheral\two_set_adv\firmware\two_set_adv.X\two_set_adv.mc3
.Note: 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-152. Project Graph
Verifying Advertisement
-
Select the BLE Stack component in the Project Graph and configure the following in the Configuration Options panel.
- Advertising
Set1
- Advertising Set2
- Advertising
Set1
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
After generating the program source from the MCC interface by clicking Generate Code, the BLE configuration source and header files can then be found in the following project directories.
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. Initialization routine executed during program initialization can be found in the project file.
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.
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 | GAP, GATT, SMP and L2CAP event handlers |
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.h
contains 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_INIT
inapp.c
User Application Development
Include
- Include the user action. For more information, refer to User Action from Related Links.
definitions.h
must be included in all the files where UART will be used to print debug information.
definitions.h
is not
specific to UART but instead must be included in all the application source files
where any peripheral functionality will be exercised.Configure 2 set of Advertisements
-
APP_BleConfigAdvance();
//Configure advertising Set 1
advParams.advHandle = CONFIG_BLE_GAP_EXT_ADV_ADV_SET_HANDLE; /* Advertising Handle */
advParams.evtProperies = CONFIG_BLE_GAP_EXT_ADV_EVT_PROPERTIES; /* Advertising Event Properties */
advParams.priIntervalMin = CONFIG_BLE_GAP_EXT_ADV_PRI_INTERVAL_MIN; /* Primary Advertising Interval Min */
advParams.priIntervalMax = CONFIG_BLE_GAP_EXT_ADV_PRI_INTERVAL_MAX; /* Primary Advertising Interval Max */
advParams.priChannelMap = CONFIG_BLE_GAP_EXT_ADV_PRI_CHANNEL_MAP; /* Primary Advertising Channel Map */
memset(&advParams.peerAddr, 0x00, sizeof(advParams.peerAddr));
advParams.filterPolicy = CONFIG_BLE_GAP_EXT_ADV_FILT_POLICY; /* Advertising Filter Policy */
advParams.txPower = CONFIG_BLE_GAP_EXT_ADV_TX_POWER; /* Advertising TX Power */
advParams.priPhy = CONFIG_BLE_GAP_EXT_ADV_PRI_ADV_PHY; /* Primary Advertising PHY */
advParams.secMaxSkip = CONFIG_BLE_GAP_EXT_ADV_MAX_SKIP; /* Secondary Advertising Max Skip */
advParams.secPhy = CONFIG_BLE_GAP_EXT_ADV_SEC_ADV_PHY; /* Secondary Advertising PHY */
advParams.sid = CONFIG_BLE_GAP_EXT_ADV_SID; /* Advertising SID */
advParams.scanReqNotifiEnable = CONFIG_BLE_GAP_EXT_ADV_SCAN_ENABLE; /* Scan Request Notification Enable */
advParams.priPhyOptions = CONFIG_BLE_GAP_EXT_ADV_PRI_ADV_PHY_OPT; /* Primary Advertising PHY Option */
advParams.secPhyOptions = CONFIG_BLE_GAP_EXT_ADV_SEC_ADV_PHY_OPT; /* Secondary Advertising PHY Option */
BLE_GAP_SetExtAdvParams(&advParams, &selectedTxPower);
appAdvData.advHandle = CONFIG_BLE_GAP_EXT_ADV_ADV_SET_HANDLE;
appAdvData.operation = BLE_GAP_EXT_ADV_DATA_OP_COMPLETE;
appAdvData.fragPreference = BLE_GAP_EXT_ADV_DATA_FRAG_ALL;
appAdvData.advLen = CONFIG_BLE_GAP_EXT_ADV_DATA_ORIG_LEN;
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);
//Configure advertising Set 2
advParams.advHandle = CONFIG_BLE_GAP_EXT_ADV_ADV_SET_HANDLE_2; /* Advertising Handle */
advParams.evtProperies = CONFIG_BLE_GAP_EXT_ADV_EVT_PROPERTIES_2; /* Advertising Event Properties */
advParams.priIntervalMin = CONFIG_BLE_GAP_EXT_ADV_PRI_INTERVAL_MIN_2; /* Primary Advertising Interval Min */
advParams.priIntervalMax = CONFIG_BLE_GAP_EXT_ADV_PRI_INTERVAL_MAX_2; /* Primary Advertising Interval Max */
advParams.priChannelMap = CONFIG_BLE_GAP_EXT_ADV_PRI_CHANNEL_MAP_2; /* Primary Advertising Channel Map */
memset(&advParams.peerAddr, 0x00, sizeof(advParams.peerAddr));
advParams.filterPolicy = CONFIG_BLE_GAP_EXT_ADV_FILT_POLICY_2; /* Advertising Filter Policy */
advParams.txPower = CONFIG_BLE_GAP_EXT_ADV_TX_POWER_2; /* Advertising TX Power */
advParams.priPhy = CONFIG_BLE_GAP_EXT_ADV_PRI_ADV_PHY_2; /* Primary Advertising PHY */
advParams.secMaxSkip = CONFIG_BLE_GAP_EXT_ADV_MAX_SKIP_2; /* Secondary Advertising Max Skip */
advParams.secPhy = CONFIG_BLE_GAP_EXT_ADV_SEC_ADV_PHY_2; /* Secondary Advertising PHY */
advParams.sid = CONFIG_BLE_GAP_EXT_ADV_SID_2; /* Advertising SID */
advParams.scanReqNotifiEnable = CONFIG_BLE_GAP_EXT_ADV_SCAN_ENABLE_2; /* Scan Request Notification Enable */
advParams.priPhyOptions = CONFIG_BLE_GAP_EXT_ADV_PRI_ADV_PHY_OPT_2; /* Primary Advertising PHY Option */
advParams.secPhyOptions = CONFIG_BLE_GAP_EXT_ADV_SEC_ADV_PHY_OPT_2; /* Secondary Advertising PHY Option */
BLE_GAP_SetExtAdvParams(&advParams, &selectedTxPower2);
appAdvData.advHandle = CONFIG_BLE_GAP_EXT_ADV_ADV_SET_HANDLE_2;
appAdvData.operation = BLE_GAP_EXT_ADV_DATA_OP_COMPLETE;
appAdvData.fragPreference = BLE_GAP_EXT_ADV_DATA_FRAG_ALL;
appAdvData.advLen = CONFIG_BLE_GAP_EXT_ADV_DATA_ORIG_LEN_2;
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 in app.c
BLE_GAP_SetExtAdvEnable(true, 2, extAdvEnableParam);
This API is called in the Applications initialization -
APP_STATE_INIT
in app.c
.

Where to go from here
-
See BLE Connection from Related Links.