3.1.1.3 BLE Scanning Extended Advertisements
Getting Started with Central Building Blocks
Introduction
This section describes in detail the scanning of Extended Advertisements (ADV_EXT_IND, ADV_AUX_IND) on the WBZ451 Curiosity board. For a successful scan of Extended Advertisement user needs to have a broadcaster transmitting these Advertisements. In BLE, a central or observer always starts with scanning.
Using the “scan_ext_adv” application example in combination with “ext_adv” example will enable users to test features like long range (Coded PHY) and sending data (1M, 2M, Coded PHY) over extended advertisements
Users can choose to run the precompiled application example .hex
file on the WBZ451 Curiosity Board and experience the demo or go
through the steps involved in developing this application from scratch
Recommendation is to follow the examples in order, by learning the basic concepts first and then progressing to the more advanced topics.
Recommended Reading
Hardware Requirement
Tool | Quantity |
---|---|
WBZ451 Curiosity Board | 2 |
Micro USB cable | 2 |
SDK Setup
Software Requirement
Smart phone App
None
Programming the Precompiled
.hex
File or Application Example
Programming the
.hex
File using MPLAB X IPE
- Central Device – Precompiled
.hex
file is located in"<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\ble\building_blocks\central\scan_ext_adv\hex"
folder - Peripheral Device – Precompiled
.hex
file is located in"<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\ble\building_blocks\peripheral\ext_adv\hex"
folder - For more details on the steps, go
to Programming a DeviceNote: Users must choose the correct device and tool information
- Follow steps mentioned in the Running a Precompiled Example document
- Central Device – Open and program
the Application Example
scan_ext_adv.X
located in "<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\ble\building_blocks\central\scan_ext_adv\firmware"
using MPLAB X IDE - Peripheral Device – Open and
program the Application Example
ext_adv.X
located in "<<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\ble\building_blocks\peripheral\ext_adv\firmware
" using MPLAB X IDE
For more details on finding the Harmony content path, refer to Installing the MCC Plugin
Demo Description
This application example enables users to do scanning of extended advertisements
(ADV_EXT_IND
, ADV_AUX_IND PDU'
s). Scanning of
CODED PHY (125 kbps) is enabled by default in the application. After programming the
application example, on Reset "ExtAdv Scan Enable Success" will be printed in the
terminal window and if there is a broadcaster sending extended advertisements the
Green LED will toggle. If this broadcaster is another WBZ451 module programmed with “ext_adv.X
” example it will
print the application data sent in auxiliary packet - ADV_AUX_IND
on TeraTerm. Toggling of Green LED denotes the reception of extended
advertisements.
- Baud Rate/Speed – 115200 (as configured in SERCOM configuration)
- Parity – None
- Data Bits – 8
- Stop Bits – 1
- Flow Control – None
Testing
Users must use another WBZ451 Curiosity board configured as BLE Ext Adv
This section assumes that a user has already programmed the ext_adv
and
scan_ext_adv
application on two WBZ451 Curiosity boards.
- Board 1 – WBZ451 Curiosity board programmed with Ext Adv
- Open TeraTerm and
configure as mentioned below:Terminal Settings
- Baud Rate/Speed – 115200 (as configured in SERCOM configuration)
- Parity – None
- Data Bits – 8
- Stop Bits – 1
- Flow Control – None
- Reset the board, Upon reset, "Ext Adv Enable" message is displayed on the TeraTerm.
- Open TeraTerm and
configure as mentioned below:
- Board 2 – WBZ451 Curiosity Board Programmed with
Scan Ext Adv
- Open TeraTerm and
configure as mentioned below:Terminal Settings
- Baud Rate/Speed – 115200 (as configured in SERCOM configuration)
- Parity – None
- Data Bits – 8
- Stop Bits – 1
- Flow Control – None
- Reset the board. Upon reset, "ExtAdv Scan Enable Success" message is displayed on the TeraTerm.
- "Microchip" message will be displayed as soon the WBZ451 module performs an extended advertisement scan.
- Open TeraTerm and
configure as mentioned below:
Developing the Application from Scratch using MCC
This section explains the steps required by a user to develop this application example from scratch using MCC
- Create a new MCC Harmony Project. For more details, refer to Creating a New MCC Harmony Project section.
- 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_pic32cxbz2_wbz45\apps\ble\building_blocks\central\scan_ext_adv\firmware\scan_ext_adv.X\"
For more details on importing the component configuration, refer to Importing Existing App Example ConfigurationNote: Import and export functionality of component configuration will help users to start from a known working setup of configuration. Accept dependencies or satisfiers, select Yes
- Verify if the project graph window has all the expected configuration, as illustrated in the following figure.
Verifying Scan Configuration
- Click on the BLE_Stack component in project graph, to open component configuration and configure as illustrated in the following figure.
Generating a Code
For more details on code generation, refer to MPLAB Code Configurator(MCC) Code Generation.
Files and Routines Automatically Generated by the MCC
app_ble.c
Configuration for scanning extended advertisements is autogenerated
Source Files | Usage |
---|---|
app.c | Application State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations |
| Source Code for the BLE stack related component configurations,
code related to function calls from app.c |
| All GAP, GATT, SMP and L2CAP Event handlers |
app_user_edits.c | User Code Change instruction |
Note:app.c
is auto generated and has a state machine based application code sample. Users can use this template to develop their application.
Header Files
ble_gap.h
(Header Files\config\default\ble\lib\include\
) - This header file contains BLE GAP functions and is automatically included in theapp.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 stateAPP_STATE_INIT
inapp.c
User Application Development
Include
definitions.h
in all the files where UART will be used to print debug information
Note:definitions.h
is not specific to just UART peripheral, instead it must be included in all application source files where peripheral functionality will be exercised
User action is required as mentioned User Action
Enabling Scanning of Extended Advertisement
BLE_GAP_SetExtScanningEnable (
BLE_GAP_SCAN_MODE_OBSERVER, &extScan
);
APP_STATE_INIT
in
app.c
// Enable Scanning the Ext Adv
uint16_t ret;
BLE_GAP_ExtScanningEnable_T extScan;
extScan.duration = 0x0;
extScan.enable = true;
extScan.filterDuplicates = BLE_GAP_SCAN_FD_DISABLE;
extScan.period = 0x0000;
ret = BLE_GAP_SetExtScanningEnable(BLE_GAP_SCAN_MODE_OBSERVER, &extScan );
if (ret == MBA_RES_SUCCESS)
SERCOM0_USART_Write((uint8_t *)"ExtAdv Scan Enable Success\r\n", 28);
app.c
Configuring LED
- Click on the System component in project graph, open Configuration Options and enable the following configurations.
- Code will be added to
GPIO_Initialize()
available inSource Files\config\default\peripheral\gpio\plib_gpio.c
.
Scanning Results
BLE_GAP_EVT_EXT_ADV_REPORT
event is generated upon finding advertisements on legacy channels
// code snippet to print ext adv data
// GPIO will toggle if it can scan any EXT ADV PDU near based on BLE_GAP_SCAN_PHY chosen
GPIOB_REGS->GPIO_PORTINV = 0x08;
// length value of 19 is chosen as a filter as ext_adv example sends 19 bytes of data
// user can modify filter mechanism based on their requirements
if (p_event->eventField.evtExtAdvReport.length == 19)
{
SERCOM0_USART_Write((uint8_t *)"\r\n", 2);
SERCOM0_USART_Write(&p_event->eventField.evtExtAdvReport.advData[5], 9);
}
app_ble_handler.c
Users can exercise various other BLE Scanning functionalities by using BLE Stack API.
For more details, refer to Getting Started with Central Building Blocks section.