2. Analyzing The Demonstration Example

This section analyzes an application example which demonstrates using advertising functionality. The example is based on the ble_adv sample code found in the SDK. It uses the default application task, named ble_adv_demo_task, used for performing advertising functionality.

  1. When no address is provided by the developer the Bluetooth public address is used. The default value of the public address is declared in sdk/ble/config/ble_config.h file. If a new value is required to be defined then the new macro definition should take place in config/custom_config_xxx.h file where all custom definitions should be declared.

/*
 * Add this macro definition in custom_config_xxx.h file to overwrite the
 * default public address. The address will be displayed in reverse order:
   06-05-04-03-02-01
 */
 #define defaultBLE_STATIC_ADDRESS   {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}

User if free to change the private Bluetooth address of the Dialog chip as well:

/*Initialize the BLE structure related to BD address value*/

static const own_address_t user_bd_address = {
   .addr_type = PRIVATE_STATIC_ADDRESS,
   .addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
};

/*Set BD address to the preferred value*/
ble_gap_address_set(&user_bd_address, 0x00FF);

Note

The BLE device address must be of type private. If this is not done, the default public BLE address is used.

  1. The channel map defined by the Bluetooth Core Specification consists of 37 data channels and 3 advertising channels used for device discovery. The latter are allocated in different parts of the spectrum to prevent interference from concurrent activities in the ISM Band. Specifically a Bluetooth low energy device can advertise on channels 37, 38, and 39 which correspond to frequencies of 2.402 MHz, 2.2426 MHz, and 2.480 MHz respectively. SmartBond™ devices advertise successively in all enabled channels. By default, all advertising channels are enabled. However, user is free to select the advertising channels enabled and utilized by the Dialog chip.

/* Set advertising channel map */

gap_adv_chnl_t channel_map = GAP_ADV_CHANNEL_37;

ble_gap_adv_chnl_map_set(channel_map);
  1. The advertising interval is the period for which a Bluetooth low energy peripheral device advertises. In this demonstration example two different time slots are defined: one at a high-speed mode and another at a lower speed. User can switch between the two aforementioned modes through FAST_ADV_INTERVAL:

/* Advertising interval slots */
#if (FAST_ADV_INTERVAL == 1)
   static const uint16_t min = BLE_ADV_INTERVAL_FROM_MS(80);
   static const uint16_t max = BLE_ADV_INTERVAL_FROM_MS(100);
#else
   static const uint16_t min = BLE_ADV_INTERVAL_FROM_MS(1000);
   static const uint16_t max = BLE_ADV_INTERVAL_FROM_MS(1500);
#endif
  1. User if free to declare the advertising data:

/*Bluetooth low energy adv demo advertising data*/

static const uint8_t adv_data[] = {
0x14, GAP_DATA_TYPE_LOCAL_NAME,
'H', 'o', 'w', ' ', 'A', 'r', 'e', ' ', 'Y', 'o', 'u', ' ', 'T', 'o', 'd', 'a',
'y', ' ', '?'
};

Note

The first element of the array is the size of the data to be sent plus an extra null character, that is, 19 + 1 = 20 elements or 0x14 in hexademical format. If the wrong value is given, it is likely that Bluetooth low energy device will not advertise at all so care must be taken when calculating this value.

  1. The peripheral device, which is advertising, assumes the role of a slave device, while the scanner device, which is searching for a device to connect to, assumes the role of a master device upon a connection process. The latter, is responsible for performing various mandatory actions including which channel to transmit and what event interval to use. However, following a successful connection, the slave device can propose its own preferred parameters via an update connection parameter request. After that, the master responds to the slave if its demands has been approved.

'Update connection parameters 1'

Figure 3 Connection Parameter Update

Note

There are some restrictions with regard to the timing intervals. For example, for an iOS platform the Interval Min must be different from the Interval Max.

In the target application example, when a connection event is issued by the BLE stack the handle_evt_gap_connected() routine is executed. In this routine a one-time software timer is created with 5 seconds timeout. When it expires, a callback function is called and the update connection parameter process takes place (conn_param_update()).