This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can I call "sd_ble_gatts_hvx" several time without waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE

Hello,

We are developing a feature on our product that allows us to dump data from an external flash memory. 

I'm using a custom characteristic with notification to dump the data over BLE. 

If i'm calling sd_ble_gatts_hvx and then waiting for the BLE_GATTS_EVT_HVN_TX_COMPLETE before calling again sd_ble_gatts_hvx, all is working fine, but the transfer is very slow and it seems to be limited by the connection interval (that is supposed to be fixed by the central : 7.5ms with a NRF52840 dongle, 30ms with my pixel 6). I'm sending packet of 180 bytes.

==>  sd_ble_gatts_hvx

==>  wait BLE_GATTS_EVT_HVN_TX_COMPLETE 

==>  sd_ble_gatts_hvx

==>  wait BLE_GATTS_EVT_HVN_TX_COMPLETE 

==>  [...]

Then, I tried something else. At the bery begining of the transfer, i'm calling sd_ble_gatts_hvx 3 times (without waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE), then the transfer continue as previously (waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE before calling again sd_ble_gatts_hvx)

==>  sd_ble_gatts_hvx

==>  sd_ble_gatts_hvx

==>  sd_ble_gatts_hvx

==>  wait BLE_GATTS_EVT_HVN_TX_COMPLETE 

==>  sd_ble_gatts_hvx

==>  wait BLE_GATTS_EVT_HVN_TX_COMPLETE 

==>  sd_ble_gatts_hvx

==>  wait BLE_GATTS_EVT_HVN_TX_COMPLETE 

==>  [...]

In that case, I have noticed that the transfer is going much faster ! I know that sd_ble_gatts_hvx can befferize data, but why is it faster ?  I want to know if i'm doing something wrong by calling sd_ble_gatts_hvx several time while it returns NRF_SUCCESS without waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE.

Thank you in advance,

Best regards,

Aurélien

  • Hello Aurélien,

    It is perfectly fine to call sd_ble_gatts_hvx() several times. Just take note of the return value. If it returns NRF_SUCCESS, it is fine, but if it returns NRF_ERROR_RESOURCES, it means that that packet was not queued successfully.

    Please also note that the BLE_GATTS_EVT_HVN_TX_COMPLETE may hold several ACKs, so try calling sd_ble_gatts_hvx() as many times as possible after each COMPLETE event if you want maximum throughput. 

    Best regards,
    Edvin

Related