3.1.1.3 BLE Scanning Extended Advertisements

Getting Started

Getting Started with Central Building Blocks

Introduction

This document describes in detail the scanning of Extended Advertisements (ADV_EXT_IND, ADV_AUX_IND) on 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.

Usage of 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 run the precompiled Application Example hex file on the WBZ451 Curiosity Board and go through the steps involved in developing this Application from scratch

It is recommend to follow the examples in order, by learning the basic concepts first and then progressing to the more advanced topics.

Hardware Requirement

Tool Quantity
WBZ451 Curiosity Board2
Micro USB cable2

SDK Setup

  1. Getting Started with Software Development

Software Requirement

  1. TeraTerm

Smartphone App

None

Programming the Precompiled Hex File or Application Example

Programming the hex file using MPLABX IPE

  1. Precompiled Hex file is located in "<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\ble\building_blocks\central\scan_ext_adv\hex" folder

  2. For more details on the steps, go to Programming a Device

    Note: Users must choose the correct Device and Tool information

Programming the Application using MPLABX IDE

  1. Follow steps mentioned in of Running a Precompiled Example document

  2. 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 MPLABX IDE

For more details on how to find 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 example it will print the Application Data sent in Auxiliary packet - ADV_AUX_IND on TeraTerm (115200, Data: 8-bit, Parity: none, stop bits: 1 bit, Flow control: none). Green LED toggles denote the reception of Extended Advertisements.

Testing

Users should 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 2 WBZ451 Curiosity Boards.

Board1: WBZ451 Curiosity Board with Ext Adv Programmed

Board 2: WBZ451 Curiosity Board with Scan Ext Adv Programmed

Board1: Open TeraTerm (Speed: 115200, Data: 8-bit, Parity: none, stop bits: 1 bit, Flow control: none). Reset the board. Upon reset, "Ext Adv Enable" message is displayed on the TeraTerm.

Board 2: Open TeraTerm (Speed: 115200, Data: 8-bit, Parity: none, stop bits: 1 bit, 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.

Data from advertiser is sent every 2 secs, Green LED is toggled when the observer device receives these extended advertisements.

Developing the Application from Scratch using MPLAB Code Configurator

This section explains the steps required by a user to develop this application example from scratch using MPLABx Code Configurator

Note: It is recommended that new users of MPLAB Code Configurator go through the overview .
  1. Create a new MCC Harmony Project. For more details, refer to 2.5 Creating a New MCC Harmony Project

  2. 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 how to import the component configuration , refer 14.3 Importing Existing App Example Configuration
    Note: Import and Export functionality of component configuration will help users to start from a known working setup of configuration.
  3. Accept Dependencies or satisfiers, select Yes

  4. Verify if the Project Graph window has all the expected configuration.

Verifying Scan Configuration

  1. Select BLE_Stack component in project graph

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 excuted during Application Initialization can be found in project files. This intitialization routine is automatically generated by the MCC. This call initializes and configures the GAP, GATT, SMP, L2CAP and BLE middleware layers.

Configuration for scanning extended advertisements is autogenerated

Source FilesUsage
app.cApplication State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations

app_ble\app_ble.c

Source Code for the BLE stack related component configurations, code related to function calls from app.c

app_ble\

app_ble_handler.c
All GAP, GATT, SMP and L2CAP Event handlers

app_user_edits.c
User Code Change instruction
Note: app.c is autogenerated 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 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

  • 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 should 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 in app.c

Configuring LED

Add the following piece of code in GPIO_Initialize() available in - Source Files\config\default\peripheral\gpio\plib_gpio.c

    GPIOB_REGS->GPIO_LAT = 0x0; /* Initial Latch Value */
    GPIOB_REGS->GPIO_TRISCLR = 0x8; /* Direction Control */
    GPIOB_REGS->GPIO_ANSELCLR = 0x8; /* Digital Mode Enable */

Scanning Results

  • BLE_GAP_EVT_EXT_ADV_REPORT event is generated upon finding Adverstisements 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);
    }

Users can exercise various other BLE Scanning functionalities by using BLE Stack API

For more details, refer to Getting Started with Central Building Blocks