How to configure the number of packets per every BLE connection interval

This blog is to show the method how to configure the number of packets per each connection interval. Basically, it is very similar to the blog (https://jimmywongiot.com/2019/12/15/how-to-set-the-bandwidth-on-ble-link-connection/).

I would give more details how to achieve for example 3 packet per connection interval.

3 packets per each connection interval

Suppose on the Nordic nRF5 SDK, it has the MACRO NRF_SDH_BLE_GAP_EVENT_LENGTH.

It was introduced since Softdevice S132v4.0 or later. It can assign the timing for each connection.

// <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 6
#endif

Example

Here is the example how to send 3 packets per each connection interval (7.5ms)

Connection interval = 7.5ms

Duration of each packet DLE = 251, MTU = 247 at 2Mbps ~= 1.4ms

Timing on DLE = 251 bytes given Bluetooth 4.2 (1Mbps) and Bluetooth 5.0 (2Mbps)
Timing through the Sniffer trace ~1.4ms (DLE = 251, MTU = 247)

Radio Notification

What is Radio Notification? – Nordic DevZone

  • Radio notification allows the application to receive an interrupt (SWI1) before, after or both before and after a scheduled radio event is happening. This event can be a connection event, advertising event, timeslot event or flash operation. This way the application can synchronize application logic with the radio operations.

https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/radio-notification

The application layer can get the RADIO activity through its notification. By setting difference distance between the RADIO is active, the application would be early alert.

BLE Radio activity with the Radio notification (SW interrupt)

In order to set the number of packets per connection interval,

Step 1:

#define MAXIMUM_NUMBER_PACKET_PER_INTERVAL 3

Step 2: Initialize the Radio notification

static void radio_notification_init(void)
{
        ble_radio_notification_init(APP_IRQ_PRIORITY_LOW_MID,                 NRF_RADIO_NOTIFICATION_DISTANCE_800US, radio_notification_handler);
}


static ble_radio_notification_evt_handler_t radio_notification_handler(bool radio_active)
{
        if (!radio_active)
        {
                m_number_of_packets_per_interval = MAXIMUM_NUMBER_PACKET_PER_INTERVAL;

        }
        else
        {

        }
}

Step 3:

static uint32_t data_transmit_single_packet(uint8_t *send_data, uint16_t len)
{
        uint32_t err_code = NRF_SUCCESS;
        uint16_t length = len;

        if (m_number_of_packets_per_interval <= 0)
            return NRF_EXCEED_NUMBER_PACKETS;                        
            
        // Send data back to the peripheral.
        err_code = ble_nus_c_data_send(&m_ble_nus_c, m_test_buffer, length);
        if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY) && (err_code != NRF_ERROR_RESOURCES))
        {
                NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", err_code);
                APP_ERROR_CHECK(err_code);
        }
        m_number_of_packets_per_interval--;

        if (err_code != NRF_ERROR_RESOURCES)
              throughput_measure_send_update(length);

        return NRF_ERROR_RESOURCES;
}

Step 4: Loop to send the data at the main thread

Welcome to give me some comments and feedback.

6 thoughts on “How to configure the number of packets per every BLE connection interval

  1. As I understand if I call data_transmit_single_packet() for fourth packet in one connection interval this function will check m_number_of_packets_per_interval and return success, but data won’t send. Is it correct behavior?

    Like

    1. Yes, it should return the NRF_EXCEED_NUMBER_PACKETS instead of NRF_SUCCESS.

      Because it has exceed the number of packets per interval.

      static uint32_t data_transmit_single_packet(uint8_t *send_data, uint16_t len)
      {
      uint32_t err_code = NRF_SUCCESS;
      uint16_t length = len;

      if (m_number_of_packets_per_interval <= 0)
      return NRF_EXCEED_NUMBER_PACKETS;

      Like

  2. about ble_radio_notification_evt_handler_t .(for the old nordic sdk)
    could be use BLE_EVT_TX_COMPLETE event ?
    and when Between connect interval , ble stack should be queue?

    Like

    1. the key point is that you don’t know the timing on each connection interval.
      You don’t have the reference point and then use the TX Complete to tune the number of packets per connection interval.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.