5.1.1.3 BLE Scanning Extended Advertisements
This section describes in detail the scanning of Extended Advertisements (ADV_EXT_IND, ADV_AUX_IND) on the WBZ351 Curiosity board. For a successful scan of Extended Advertisement user needs to have a broadcaster transmitting these Advertisements. In Bluetooth Low Energy, a central or observer always starts with scanning.
Using the scan_ext_adv application example in combination with ext_adv
example enables the users to test features like long range (Coded PHY) and sending data
(1M, 2M, Coded PHY) over extended advertisements.
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.
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 Central Devices from Related Links.
-
FreeRTOS and BLE Stack Setup – See Central - 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 | WBZ351 Curiosity Board | 2 |
| 2 | Micro USB cable | 2 |
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 Application
None
Programming the Precompiled Hex File or Application Example
Using MPLAB® X IPE:
- Central Device – Import and
program the precompiled hex file:
.<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\central\scan_ext_adv\hex - Peripheral Device – Import and
program the precompiled hex file:
<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\ext_adv\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.
- Central Device – Open and program
the application
scan_ext_adv.Xlocated in<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\central\scan_ext_adv\firmware. - Peripheral Device – Open and
program the application
ext_adv.Xlocated in.<Discover Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\ext_adv\firmware -
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
This application example enables users to scan for extended advertisements
(ADV_EXT_IND, ADV_AUX_IND PDUs). Scanning of
the CODED PHY (125 kbps) is enabled by default in the application. After programming
the application example, upon Reset, “ExtAdv Scan Enable Success” will be printed in
the terminal window and if there is a broadcaster sending extended advertisements
the Green LED toggles. If this broadcaster is another WBZ351 Module programmed with ext_adv.X example it prints
the application data sent in auxiliary packet ADV_AUX_IND on Tera
Term. Toggling of the green LED indicates 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 WBZ351 Curiosity Board configured as BLE Extended Advertisements, see BLE Extended Advertisements from Related Links.
This section assumes that a user has already programmed the ext_adv
and scan_ext_adv application on two WBZ351 Curiosity boards.
- Board 1 – WBZ351 Curiosity board programmed with extended
advertisements
- Open Tera Term 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, the
Ext Adv Enablemessage appears on the Tera Term.
- Open Tera Term and
configure as mentioned below:
- Board 2 – WBZ351 Curiosity Board Programmed with extended
advertisements scan
- 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, the
ExtAdv Scan Enable Successmessage appears on the Tera Term. Microchipmessage will be displayed as soon the WBZ351 Module performs an extended advertisement scan.
- Open TeraTerm and
configure as mentioned below:
Developing the Application from Scratch using MCC
- Create a new harmony project. For more details, see Creating a New MCC Harmony Project from Related Links.
- Import Component Configuration -
This step helps users to setup the basic components and configuration required
to develop this application. The imported file is of format
.mc4and is located in the path. 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\central\scan_ext_adv\firmware\scan_ext_adv.X\Note: Import and export functionality of component configuration will help users to start from a known working setup of configuration. - Accept Dependencies or Satisfiers.
- If prompted to resolve dependencies or add required modules. Click Yes.
- MPLAB® MCC automatically adds any required drivers or middleware.
- Verify Project Graph.In Project Graph window, confirm that all expected components are present. For more details, see the following figure.
Figure 5-22. Project Graph
Verifying Scan Configuration
- Open the Project Graph
- In MPLAB® X IDE, with MCC open, locate the Project Graph tab. In the Project Graph tab, the user can see all the components and their relationships to the project.
- Select the BLE Stack
Component
- Click on the BLE Stack component in project graph. This opens the “BLE Stack” component Configuration Options tab.
- In the “BLE Stack”
Configuration Options tab, the user can set the parameters as
per the requirement illustrated in the following figure.
Figure 5-23. BLE Stack Configuration
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.capp_ble.c| 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. | |
ble_gap.h(Header Files\config\default\ble\lib\include\) - This header file contains BLE GAP functions and is automatically included in theapp.cfile
-
- MCC generates and
adds the code to initialize the BLE Stack GAP, GATT, L2CAP and SMP
in the
APP_BleStackInit()function. APP_BleStackInit()is the API that will be called inside the application’s Initial stateAPP_STATE_INITinapp.c.
- MCC generates and
adds the code to initialize the BLE Stack GAP, GATT, L2CAP and SMP
in the
User Application Development
- Include the user action. For more information, refer to User Action from Related Links.
definitions.hin all the files where UART will be used to print debug information.Note:definitions.his not specific to just UART peripheral, instead it must be included in all application source files where peripheral functionality will be exercised.
- Enabling Scanning of
Extended Advertisement
BLE_GAP_SetExtScanningEnable(BLE_GAP_SCAN_MODE_OBSERVER, &extScan);
- API’s mentioned in
this section are called in the Applications Initial state,
APP_STATE_INIT, inapp.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);
Figure 5-27. app.c
- Configuring LED
- Click on the System component in project graph. This opens Configuration Options tab and enable the following configurations.
- Code will be added to
GPIO_Initialize()available inSource Files\config\default\peripheral\gpio\plib_gpio.c.
Figure 5-28. System Component Configuration
- Scanning Results
BLE_GAP_EVT_EXT_ADV_REPORTevent 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); }Figure 5-29. app_ble_handler.c
Note: Users can explore more BLE Advertisement functionalities using the BLE Stack APIs. For more information, refer to BLE Stack in Reference Documentation from Related Links.
Where to Go from Here
See Central Devices from Related Links.
