Transmission rate of BLE

The master device transmits data to the slave device. In order to achieve the maximum transmission rate, write CMD (write command, no response from the slave device) can be used to write data to the slave device; The slave device sends data to the master device. In order to achieve the maximum transmission rate, notification can be used

This code takes nordic platform as an example

Main factors affecting transmission rate

  • Connection interval
  • Number of packets transmitted between connections
  • Packet size

1 connection interval

If CLE is enabled (it is not limited to sending only 4 ~ 6 packets in a single connection interval), so you only need to select an appropriate connection interval without using low-power Bluetooth 5 Minimum connection interval in X protocol stack (7.5ms). However, it should be noted that NRF_SDH_BLE_GAP_EVENT_LENGTH is greater than or equal to the connection interval. According to the reference data given by Nordic protocol stack, when the actual connection interval is 50ms or 400ms, the corresponding transmission rates are 1327.5 kbps and 1376.2kbps respectively.

Therefore, the connection interval can be set like this

#define CONN_INTERVAL_MIN               (uint16_t)(MSEC_TO_UNITS(50, UNIT_1_25_MS))    /**< Minimum acceptable connection interval, in units of 1.25 ms. */
#define CONN_INTERVAL_MAX               (uint16_t)(MSEC_TO_UNITS(60, UNIT_1_25_MS))    /**< Maximum acceptable connection interval, in units of 1.25 ms. */


2 number of packets transmitted between connections

There are two parameters that affect the connection interval and the number of packets

  • CLE
  • Connection event length

2.1 CLE

CLE is the abbreviation of Connection Event Length Extension, which indicates the extension of connection event length. In the 4.0 protocol, a single connection event can only send up to 4 (IOS) or 6 (Android) packets. When CLE is adopted, the protocol stack will judge whether data packets can be sent in the remaining time of the connection interval. If data packets can be sent, data will continue to be sent without limiting the number of data packets.

Start the CLE after the initialization of the protocol stack is completed

//When status is true, open CLE
void conn_evt_len_ext_set(bool status)
{
    ret_code_t err_code;
    ble_opt_t  opt;

    memset(&opt, 0x00, sizeof(opt));
    opt.common_opt.conn_evt_ext.enable = status ? 1 : 0;

    err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
    APP_ERROR_CHECK(err_code);
}

2.2 length of connection event

Length of connection event, unit: 1.25ms, NRF_SDH_BLE_GAP_EVENT_LENGTH, available on SDK_ config. Modified in H, this value can be equal to the connection interval

// <o> NRF_SDH_BLE_GAP_EVENT_LENGTH - GAP event length. 
// <i> The time set aside for this connection on every connection interval in 1.25 ms units.
#ifndef NRF_SDH_BLE_GAP_EVENT_LENGTH
#define NRF_SDH_BLE_GAP_EVENT_LENGTH 400
#endif

3 packet size

Two parameters can affect the packet size

  • ATT_MTU
  • DLE

3.1 ATT_MTU size

4.0 protocol maximum 23 bytes, 5.5 bytes Maximum att supported by X protocol_ The size of MTU is 247 bytes, which can be displayed on SDK_ config. Modified in H

// <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size. 
#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
#endif

3.2 DLE

Currently ble 5 The maximum DLE supported by X protocol is 251, which can be accessed on SDK_ config. Modified in H

// <i> Requested BLE GAP data length to be negotiated.
#ifndef NRF_SDH_BLE_GAP_DATA_LENGTH
#define NRF_SDH_BLE_GAP_DATA_LENGTH 251
#endif

4 use 2M PHY

At present, BLE supports three kinds of Le phys, namely LE 1M PHY, LE 2M PHY and LE CODED PHY. LE 2M PHY is used for high-speed rate, while the theoretical distance is half of LE 1M PHY, while LE CODED PHY is used for long-distance mode. LE 1M PHY takes into account distance and rate, and can be selected according to its actual needs. If there are requirements for transmission distance, it needs to be selected carefully.

LE PHY can call SD_ ble_ gap_ phy_ The update (uint16_t conn_handle, ble_gap_phys_t const * p_gap_phys) interface initiates the update, which is generally received at the peripheral end_ evt_ Request update when the connected event occurs. As shown below, it can be configured to support only 2M PHY:

static test_params_t m_test_params =
{
    .phys.tx_phys             = BLE_GAP_PHY_2MBPS,
    .phys.rx_phys             = BLE_GAP_PHY_2MBPS,
};
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t              err_code;
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            //Only the phy update part is written here, and others are omitted
             err_code = sd_ble_gap_phy_update(p_gap_evt->conn_handle, &m_test_params.phys);
             APP_ERROR_CHECK(err_code);
            break;
    }
 }

5 increase the queue buffer of protocol stack

When there is free space in RAM, a larger queue buffer can be configured for the protocol stack. The default value of queue buffer is 1, which can be configured according to the actual situation

// <o> NRF_SDH_BLE_TOTAL_LINK_COUNT- Total link count.
//<i> Maximum number of total concurrent connections using the default configuration.
#ifndef NRF_SDH_BLE_TOTAL_LINK_COUNT
#define NRF_SDH_BLE_TOTAL_LINK_COUNT 7 
#endif

Tags: BLE Nordic

Posted by vaaaska on Fri, 13 May 2022 04:00:13 +0300