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

Handling NRF_ERROR_RESOURCE via checking for BLE_GATTS_EVT_HVN_TX_COMPLETE

Hello

I'm currently running ble_app_uart__saadc_timer_driven__scan_mode and would like to modify it for faster sampling rate. However, NRF_ERROR_RESOURCE presents an obstacle for the BLE tranmission as higher sampling rate would produce too many packet and overload the buffer. Reading through the forum posts on similar subject, I came upon the solution of expanding the tx queue's size and having the program wait for  BLE_GATTS_EVT_HVN_TX_COMPLETE before continuing sending.

For my approach, I add a case in on_ble_evt() to handle the BLE_GATTS_EVT_HVN_TX_COMPLETE event, setting the global flag queueIsFull=0. In saadc_callback(), after ble_nus_string_send is called, I try to implement the waiting procedure in the following manner:
if (err_code == NRF_ERROR_RESOURCES){
          queueIsFull=1;
}
while(queueIsFull==1){
          nrf_delay_ms(5);
}

The program is stuck in a while loop. From what I can tell, on_ble_evt() can not be triggered inside the while loop. Is there a better implementation for waiting on BLE_GATTS_EVT_HVN_TX_COMPLETE?

  • Hi,

    Is there a better implementation for waiting on BLE_GATTS_EVT_HVN_TX_COMPLETE?

    Take a look at how it is implemented in the ble_app_att_mtu_throughput example, in amts.c

    Snippet:

            err_code = sd_ble_gatts_hvx(p_ctx->conn_handle, &hvx_param);
    
            if (err_code == NRF_ERROR_RESOURCES)
            {
                // Wait for BLE_GATTS_EVT_HVN_TX_COMPLETE.
                p_ctx->busy = true;
                break;
            }

Related