| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ANT Background Scanning
This example requires the following SoftDevice: S212

Important: Before you run this example, make sure to program the SoftDevice.

The ANT Background Scanning Example shows how to implement a background scanning channel in combination with a master channel on a single device. It also demonstrates how to use extended messages to obtain Received Signal Strength Indication (RSSI) and channel ID information from received packets.

# Description

Background scanning channels in ANT are searching channels that never synchronize with a master. Instead of acquiring a master, ANT will pass the data to the master and continue searching. These channels allow for asynchronous topologies with other channels running independently on the same device. For more information about background scanning channels and channel parameters, see the ANT Message Protocol and Usage documentation and the ANT Channel Search application note.

This example uses two channels: one background scanning channel that can receive data from multiple devices and one master channel. The master channel in this example copies the received RSSI and channel ID information and mirrors these parameters back to the transmitting devices.

Background scanning and transmitting on master with two nodes

After startup or reset, each ANT node opens one background scanning channel and one master channel. The background scanning channel is configured similar to a regular slave channel, but with a special flag set to denote its function. The search time-out is set to infinity to ensure that the background scanning channel continues searching for other channels. When a packet is received, the node will indicate the BSP_INDICATE_RCV_OK state and print information about the sender (signal strength and channel ID).

The following table lists the ANT channel parameters for the master channel and the background scanning channel (numbers in parentheses denote the parameters that should be used to set the values):

Parameter | Master channel | Background scanning channel
--- | --- | ---
Channel type | Master (0x10) | Slave(0x00)
Extended assignment | N/A | EXT_PARAM_ALWAYS_SEARCH (0x01)
Network key | Public | Public
RF channel | 77 (2477 MHz) | 77 (2477 MHz)
Channel period | 2048 (16 Hz) | N/A
Device number | Serial number | Wildcard (0)
Device type | 1 | 1
Transmission type | 5 | 5
Search time-out (high priority) | N/A | No HP search (0)
Search time-out (low priority) | N/A | Infinite (255)

# Message format

The master channel on each device sends a single payload of data. This payload indicates the signal strength and the channel ID of the last message that was received on the background scanning channel.

The following table shows the message format of the default master message:

Byte | Description
--- | ---
0 | Page number = 1 (ANT_BEACON_PAGE)
1 | RSSI value (signed dBm value, corresponding to the device number)
2-3 | Device number of the last message that was received on the background scanning channel (little endian, corresponding to the RSSI value)
4-5 | Reserved
6 | Counter that increases with each channel period
7 | Number of messages that were received on the background scanning channel

# Setup

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\ant\ant_background_scanning`

# Testing

Note: You can use a custom channel or encryption when running any of the ANT examples. When adding a new channel or encryption, remember to update ANT stack configuration.

You can test the Background Scanning example in different ways:

- Testing the Background Scanning example using two boards
- Testing the Background Scanning example using ANTware II

## Testing the Background Scanning example using two boards

Note that UART is not available when you use the Dynastream D52 Starter Kit.

1. Start a terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
   - Baud rate: 115.200
   - 8 data bits
   - 1 stop bit
   - No parity
   - HW flow control: RTS/CTS
2. Compile and program at least two boards.
3. Observe that the boards occasionally indicate BSP_INDICATE_RCV_OK and print basic information about the sender of the message.

## Testing the Background Scanning example using ANTware II

1. Compile and program the Background Scanning application.
2. Run ANTware II. Select your ANT PC dongle (for example, ANTUSB-m) from the available devices. Configure the device channels by loading the device profile configuration from the following file: `<InstallFolder>\examples\ant\ant_background_scanning\background_scanning_test.xml`. Alternatively, you can configure the device channels manually:
   - One slave channel with device number 0. Configure the channel according to the information for the master channel as shown in the table above, but configure it to be a slave channel.
   - One master channel with a device number other than 0. Configure the channel according to the information for the master channel as shown in the table above.
     Setup of the ANT Background scanning example
3. Click the Auto-Open button. Check the message payload that is received on the slave channel. The reported device number (byte 2 and 3) is the channel ID that you configured for the master channel. The reported RSSI value (byte 1) changes when the board is moved closer or further away from the ANT USB dongle. For example:

   Payload | Description
   --- | ---
   Received BROADCAST_DATA_0x4E :: 4e, 00-01-B6-32-00-00-00-8D-74 | Device number = 50
   Received BROADCAST_DATA_0x4E :: 4e, 00-01-B6-32-00-00-00-8E-74 | RSSI = -74 dBm (further away)
   Received BROADCAST_DATA_0x4E :: 4e, 00-01-CB-32-00-00-00-8A-0C | RSSI = -53 dBm (closer)

4. You can configure more master channels in ANTware II. Each channel must use a different device number. The background scanning channel on the device will receive messages from all channels asynchronously and report the received data back to the slave channel.