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

How to handle NRF_ERROR_BUSY status?

My application code running on nrf51822 calls sd_ble_gatts_value_set to update a control characteristic. After 16 times receiving NRF_ERROR_BUSY status from this function, I would like to ensure that the control characteristic succeeds before I proceed with other tasks. So I loop like this:

v = sd_ble_gatts_hvx
if (v == NRF_ERROR_BUSY) 
  busycount++

if (busycount >= 16)
  do
    nrf_delay_ms(5)
    v = sd_ble_gatts_hvx
  while(v != NRF_SUCCESS)

But it never exits the loop. Is there a better way to handle this? How do I make sd_ble_gatts_hvx succeed again?

Parents
  • It appears that you are using the sd_ble_gatts_hvx to send an Indication. When you use an Indication you need to wait for an Confirmation from the peer GATT client, before you send the next Indication. The Confirmation is received as a BLE_GATTS_EVT_HVC event, after which you can send the next Indication. If this is not what you intended you can use the Notification with sd_ble_gatts_hvx, this will not result an NRF_ERROR_BUSY.

    You will get an acknowledgment from the peer radio when sending either Notification or Indication in the form of a BLE_EVT_TX_COMPLETE event. This event is sent as soon as the radio packet transmitted is acked by the peer.

  • Hi David,

    The connection disconnects while waiting for the BLE_EVT_TX_COMPLETE event. Could you please suggest a better way to handle the Tx/Rx data over BLE ? I am using sd_ble_gatts_hvx to send notification values. There are 16 bytes to be transmitted over the BLE, out of which only first 7 bytes get transmitted successfully and the others return the err_code of 19.

Reply
  • Hi David,

    The connection disconnects while waiting for the BLE_EVT_TX_COMPLETE event. Could you please suggest a better way to handle the Tx/Rx data over BLE ? I am using sd_ble_gatts_hvx to send notification values. There are 16 bytes to be transmitted over the BLE, out of which only first 7 bytes get transmitted successfully and the others return the err_code of 19.

Children
No Data
Related