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.

  • This is very old but must be a common problem. What is the best way to wait for that indication? Will a line of code like this just waste CPU cycles?

    while (sd_ble_gatts_hvx(m_connection_handle, &hvx_params) == NRF_ERROR_BUSY);

    Can the reason for busy be that I am already sending a sequence of notifications? For example I am sending a sequence of notifications and the client writes some command on a control point and I need to indicate that I am busy. How would I do that? Can I squeeze that in between notifications?

Reply
  • This is very old but must be a common problem. What is the best way to wait for that indication? Will a line of code like this just waste CPU cycles?

    while (sd_ble_gatts_hvx(m_connection_handle, &hvx_params) == NRF_ERROR_BUSY);

    Can the reason for busy be that I am already sending a sequence of notifications? For example I am sending a sequence of notifications and the client writes some command on a control point and I need to indicate that I am busy. How would I do that? Can I squeeze that in between notifications?

Children
No Data
Related