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

how to reduce ble_nus_string_send cost?

today simple test ble_nus_string_send time-consuming function, but found that the implementation of a ble_nus_string_send and wait for the success of transmission time-consuming about 11~13ms is a normal value? (ATT_MTU = 247, LL payload size = 31,event length =6) The time I got by calculating tick2 - tick1.

If I want to send 6 LL packets in a connection event, what should I call? Sd_ble_gatts_hvx call seems to be just a connection event sent a LL packet? I am a bit confused

APP_TIMER_DEF(test_timer);

ble_nus_on_ble_evt()
{
    .
    .
    case BLE_GATTS_EVT_HVN_TX_COMPLETE:
        tx_completeflg = 1;
    break;
    .
    .
}


main()
{
    uint32_t tick1,tick2;
    .
    .
    app_timer_start(test_timer);
    tick1 = app_timer_cnt_get();

    ble_nus_string_send();
    while(tx_completeflg ==0)
    tick2 = app_timer_cnt_get();
    app_timer_stop(test_timer);
    .
    .
}
  • Thanks,Hung Bui.

    I do not know my understanding right, in the ble_gatts.h file BLE_GATTS_HVN_TX_QUEUE_SIZE_DUFAULT this macro definition, if I want to send 6 LL packet in a conneviton event, as long as this is set to 6, and then continue to call sd_ble_gatts_hvx until NRF_ERROR_RESOURCES return, and then Waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE on it, if set to 1, can only send one LL packet.

    Another question, if I understand correctly, when I enable the Connetion event extendsion, does this macro definition make sense?

  • Yes, you should set the TX_QUEUE_SIZE to 6 or higher.

    When you enable connection event extension, it's not very important which event length you set (but you still need to set the queue size big enough). The softdevice will try to send as much as possible until the buffer is empty or when the connection event is finish.

    Most important, you need to get the connection interval to as low as possible, 7.5ms is the lowest.

    I would suggest you to have a look at our ble_app_att_mtu_throughput in the SDK.

  • Thank you very much. Your answer is very useful