Periodic Advertisement Example

Background

This code example has a related User's Guide, here: Periodic Advertising

Description

This example demonstrates the periodic advertising feature of Bluetooth 5, detailed in the Periodic Advertising User's Guide. The example consists of two projects, one for the advertiser and one for the scanner.

The advertiser starts both periodic advertising and extended advertisement to advertise the sync info needed for the periodic advertising. The advertiser changes the content of the periodic advertisement every second.

The scanner starts scanning for the extended advertisements to find the sync info, and then syncs on the periodic advertising. Once synced, the scanning is stopped and only periodic advertisements are received.

The used API commands can be found in the Periodic Advertising User's Guide.

Setting up

To try this example, you need two radio boards, one for the advertiser side and one for the scanner side.

Advertiser

  1. Create a new SoC-Empty project for your device.

  2. Copy the attached advertiser_app.c file into your project, and remove app.c from the project.

  3. Set DEBUG_LEVEL to 1 in app.h.

  4. Open GATT Configurator, and import the attached gatt.xml with the import button found on the right side.

  5. Press Save and Generate in the GATT Configurator.

  6. Build and flash the project to your device.

Scanner

  1. Create a new SoC-Empty project for your device.

  2. Copy the attached scanner_app.c file into your project, and remove app.c from the project.

  3. Set DEBUG_LEVEL to 1 in app.h.

  4. Build and flash your project to your device.

Usage

After flashing the applications to the devices, connect to the devices with a terminal program (such as TeraTerm) using the virtual COM port (JLink CDC UART), and reset both devices. On the logs you should be able to observe that that devices are sending and receiving periodic advertisements after the scanner synced on the advertiser. The advertiser changes the content of the advertisement every second, which can be observed on both sides.

Logs of the advertiser and the scanner

Use the energy profiler in Simplicity studio to evaluate the current consumption. The scanner goes into energy saving mode and wakes up every 200 ms to receive sync packets from the advertiser. The advertiser sleeps when not advertising, as shown in the figure below.

Periodic Advertisement Energy Profiler

Source