4.1.1.3 Bluetooth®LE Scanning Extended Advertisements
This section explains the scanning of Extended Advertisements
(ADV_EXT_IND, ADV_AUX_IND) on the PIC32WM-BW1 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 either run the precompiled Application Example hex file provided on the PIC32WM-BW1 Curiosity Board or follow the steps to develop the application from scratch.
Hardware Requirement
| S. No. | Tool | Quantity |
|---|---|---|
| 1 | PIC32WM-BW1 Curiosity Board | 2 |
| 2 | USB Type-C™ cable | 2 |
Software Requirement
- To install Tera Term tool, refer to the Tera Term web page listed in the Reference Documentation from Related Links.
Programming the Precompiled Hex File or Application Example
Using MPLAB® X IPE:
- Central Device – Precompiled
.hexfile is located in :<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\central\scan_ext_adv\hexfolder. - Peripheral Device – Precompiled
.hexfile is located in<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\peripheral\peripheral_ext_adv\hex” folder - 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<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\central\scan_ext_adv\firmware. - Peripheral Device – Open and
program the application
ext_adv.Xlocated in “<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\peripheral\peripheral_ext_adv\firmware”. -
For more details on finding the Harmony content path, refer to Installing the MCC Plugin from Related Links.
Testing
- Users must use two PIC32WM-BW1 Curiosity boards programmed with Extended Advertisement and Scanning Extended Advertisement applications.
- Board 1 – PIC32WM-BW1 Curiosity Board Programmed with
“ext_adv” application. Open TeraTerm and configure as mentioned below:
Terminal Settings
- Baud Rate/Speed – 115200
- Parity – None
- Data Bits – 8
- Stop Bits – 1
- Flow Control – None
- Reset the board, Upon reset,
“Ext Adv Enable” message is displayed on the Tera Term. The board behaves as
a broadcaster and is sending extended advertisements
(
ADV_AUX_IND,ADV_EXT_IND). - Board 2 – PIC32WM-BW1 Curiosity Board Programmed with
“Scan Ext Adv”. Open TeraTerm and configure as mentioned
below:
Terminal Settings
- Baud Rate/Speed – 115200
- 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 Tera Term. Scanning of CODED PHY (125 kbps) is enabled by default in the application.
- “Microchip” message will be displayed as soon as the PIC32WM-BW1 module performs an extended advertisement scan.
- The advertiser’s data may take up to 120 seconds to arrive and the Green LED toggles when the observer device receives these extended advertisement.
Project Graph
- 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.
Figure 4-20. BLE Stack Configuration
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.Figure 4-21. System Component 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 |
|
| GAP, GATT, SMP and L2CAP Event handlers |
app_user_edits.c | User code change instruction |
Note:app.cis 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.cfile
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_INITinapp.c
User Application Development
-
Include
- 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
// 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 4-25. app.ble.c -
Scanning Results
-
BLE_GAP_EVT_EXT_ADV_REPORTevent is generated upon finding advertisements on legacy channels inapp_ble_handler.c.// 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 4-26. app_ble_handler.c -
