4. Connection Parameter Update

This section describes how to initiate a connection parameter update procedure.

4.1. Introduction

It is important to understand the central/peripheral (master/slave) concept at the heart of the connected mode in the Bluetooth low energy protocol. 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 the various mandatory settings including in 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'

Fig. 6 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.

4.2. Updating Connection Parameters

Step #1 In the handle_evt_gap_connected() handler, which is triggered when a connection is established, we create a software timer with a default timeout of 5 seconds. When it expires, a callback function is called and the update connection parameter process takes place.

/* Handler for establishing a successful connection */

static void handle_evt_gap_connected(ble_evt_gap_connected_t *evt)
{
    /*
     * Manage behavior upon connection
     */
     connection_index = evt->conn_idx;

     /* Add a timer that, when expires, will renegotiate connection parameters. */
     update_timer = OS_TIMER_CREATE("conn_timer", OS_MS_2_TICKS(5000), OS_TIMER_FAIL,
                                             (uint32_t) OS_GET_CURRENT_TASK(), conn_param_timer_cb);
     OS_TIMER_START(update_timer, OS_TIMER_FOREVER);
}

Note

The second input parameter of the timer creation function (OS_TIMER_CREATE) is the timer period and has been set to 5 seconds. The last parameter is the callback function which is called when the timer expires.


Step #2 When the timer expires, the conn_params_timer_cb() callback function is triggered. This function calls the conn_param_update() function which is responsible for initiating the update connection parameters process.

/* This timer callback notifies the task that the timer for discovery, bonding, and encryption
*  has elapsed, and the connection parameters can be changed to the preferred ones.
*/
static void conn_param_timer_cb(OS_TIMER timer)
{
        /* Call the function which is responsible for the connection parameters update. */
        conn_param_update(connection_index);
}

Step #3 In the conn_param_update() function, change the parameters displayed in the code snippet:

/* Update connection parameters. */
static void conn_param_update(uint16_t conn_idx)
{
     gap_conn_params_t cp;

     cp.interval_min = defaultBLE_PPCP_INTERVAL_MIN;
     cp.interval_max = defaultBLE_PPCP_INTERVAL_MAX;
     cp.slave_latency = defaultBLE_PPCP_SLAVE_LATENCY;
     cp.sup_timeout = defaultBLE_PPCP_SUP_TIMEOUT;

     ble_gap_conn_param_update(conn_idx, &cp);
}

Step #4 In the /ble_adv/config/customer_config_qspi.h header file, define the preferred update connection parameter values.

/* Peripheral specific config */

#define defaultBLE_PPCP_INTERVAL_MIN  (BLE_CONN_INTERVAL_FROM_MS(500)) // 500 ms
#define defaultBLE_PPCP_INTERVAL_MAX  (BLE_CONN_INTERVAL_FROM_MS(750)) // 750 ms
#define defaultBLE_PPCP_SLAVE_LATENCY (0) // 0 events
#define defaultBLE_PPCP_SUP_TIMEOUT   (BLE_SUPERVISION_TMO_FROM_MS(6000)) // 6000 ms

Table 6 Update Connection Parameter Values

Macro Name

Unit

Description

defaultBLE_PPCP_INTERVAL_MIN

ms

The Central device connecting to a Peripheral device needs to define the time interval for a connection to happen. This parameter is the minimum permissible connection time value to be used during a connection event.

defaultBLE_PPCP_INTERVAL_MAX

ms

The Central device connecting to a Peripheral device needs to define the time interval for a connection to happen. This parameter is the maximum permissible connection time value to be used during a connection event.

defaultBLE_PPCP_SLAVE_LATENCY

This parameter defines the latency of the slave when responding to a connection event in consecutive connection events. This is expressed in terms of multiples of connection intervals, where only one connection event is allowed per interval.

defaultBLE_PPCP_SUP_TIMEOUT

ms

This parameter defines the LE link supervision timeout interval. It defines the timeout duration for which an LE link needs to be sustained when there is no response from the peer device over the LE link.