NRF_ERROR_BUSY while enabling several notifications

Hi Nordic, 

I  am working with the s140, sdk 15.3. My application is a central that should connect to a device that has several services. As soon as the connected event is triggered, it initiates the discovery with the ble_db_discovery_start(...). 

The first 2 characteristics notifications are enabled properly. For the 3rd characteristics, a notification is received as soon as the  device is connected, but since the notification is not enabled, an error is detected in the  BLE_GATTC_EVT_HVX event of the service.

After that, if i try to enable the notifications from that characteristics, the NRF_ERROR_BUSY error is returned from the cccd_configure().

I have read that, i should wait for the BLE_GATTC_EVT_WRITE_RSP event and from there enable again the characteristics but every time i get the same error. 

Is there something that I'm missing? The continuous NRF_ERROR_BUSY are caused by the first invalid notification received?

Any help is welcome. Thank you! 

Parents
  • Hi,

    You write that you get NRF_ERROR_BUSY from cccd_configure(), which is implemented in most service implementations.Most likely the issue is that a GATT procedure is already active, and you need to wait for it to finish. To know more we would need to know which function within cccd_configure() is it that returns this? The further down you follow this the better.

  • Since it is calling the sd_ble_gattc_write , i thought it was required to wait for the BLE_GATTC_EVT_WRITE_RSP event.

    static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
    {
        //NRF_LOG_INFO("Configuring CCCD. CCCD Handle = %d, Connection Handle = %d",  cccd_handle,conn_handle);
        uint8_t buf[BLE_CCCD_VALUE_LEN];
    
        buf[0] = enable ? BLE_GATT_HVX_NOTIFICATION : 0;
        buf[1] = 0;
    
        ble_gattc_write_params_t const write_params =
        {
            .write_op = BLE_GATT_OP_WRITE_REQ,
            .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
            .handle   = cccd_handle,
            .offset   = 0,
            .len      = sizeof(buf),
            .p_value  = buf
        };
    
        return sd_ble_gattc_write(conn_handle, &write_params);
    }

Reply
  • Since it is calling the sd_ble_gattc_write , i thought it was required to wait for the BLE_GATTC_EVT_WRITE_RSP event.

    static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
    {
        //NRF_LOG_INFO("Configuring CCCD. CCCD Handle = %d, Connection Handle = %d",  cccd_handle,conn_handle);
        uint8_t buf[BLE_CCCD_VALUE_LEN];
    
        buf[0] = enable ? BLE_GATT_HVX_NOTIFICATION : 0;
        buf[1] = 0;
    
        ble_gattc_write_params_t const write_params =
        {
            .write_op = BLE_GATT_OP_WRITE_REQ,
            .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
            .handle   = cccd_handle,
            .offset   = 0,
            .len      = sizeof(buf),
            .p_value  = buf
        };
    
        return sd_ble_gattc_write(conn_handle, &write_params);
    }

Children
  • Hi,

    Yes, then waiting for BLE_GATTC_EVT_WRITE_RSP should do the trick. Could it be that you do not have a full overview of your application, and that some you start a new GATT procedure somewhere else? Perhaps you end up somehow making two calls to sd_ble_gattc_write() after the BLE_GATTC_EVT_WRITE_RSP? That is just speculation, though.

    Have you done any debugging to see what happens? Do you get the BLE_GATTC_EVT_WRITE_RSP at some point after getting NRF_ERROR_BUSY  returned from sd_ble_gattc_write()? 

Related