This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to achieve max throughput with NUS service?

Hi All.

I have a project where my peripheral (nRF52832) connects to my central (nRF52840), and then transmits 128 byte packets continuously one after the other. It works ok, but data rate is about 5,000 bytes per second max (40,000 bps). This seems a little low. I am using the following event to trigger the message, so this should be the quickest way to send one after the other?

case BLE_NUS_EVT_TX_RDY:

            send_data();

            break;

Send data;

void send_data(void)
{
    uint8_t testData[128];
    ret_code_t err_code;

    for (uint8_t i = 0; i < 128; i++) {
       testData[i] = i;
    }
    testData[0] = P0;
    testData[1] = P1;
    testData[2] = P2;
    testData[3] = page_count;


    //TODO - Add something here so if it fails X number of times, we stop download and disconnect 
    uint16_t length = (uint16_t)128;
    err_code = ble_nus_data_send(&m_nus, testData, &length, m_conn_handle);
    if(err_code == NRF_SUCCESS)
    {
      P1++;
      if(P1 == 0) P2++;
      page_count--;
    }
}

Also here are my settings for the radio times which seem to give the best results (same on both central and peripheral);

#define MIN_CONNECTION_INTERVAL   MSEC_TO_UNITS(7.5, UNIT_1_25_MS)      /**< Determines minimum connection interval in milliseconds. */
#define MAX_CONNECTION_INTERVAL   MSEC_TO_UNITS(10, UNIT_1_25_MS)       /**< Determines maximum connection interval in milliseconds. */
#define SLAVE_LATENCY             0                                     /**< Determines slave latency in terms of connection events. */
#define SUPERVISION_TIMEOUT       MSEC_TO_UNITS(4000, UNIT_10_MS)       /**< Determines supervision time-out in units of 10 milliseconds. */

#ifndef NRF_SDH_BLE_GAP_DATA_LENGTH
#define NRF_SDH_BLE_GAP_DATA_LENGTH 251
#endif

// <o> NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - Maximum number of peripheral links. 
#ifndef NRF_SDH_BLE_PERIPHERAL_LINK_COUNT
#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1
#endif

// <o> NRF_SDH_BLE_CENTRAL_LINK_COUNT - Maximum number of central links. 
#ifndef NRF_SDH_BLE_CENTRAL_LINK_COUNT
#define NRF_SDH_BLE_CENTRAL_LINK_COUNT 0
#endif

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

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

// <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

I don't really understand the above settings to be honest, but from what I have read should give the best throughput. However 40kbps seems a bit slow considering both ends are nRF52 devices?

Thanks

Phil

Parents Reply Children
No Data
Related