I am not getting a BLE_GATTC_EVT_WRITE_RSP event after writting to the CCCD.

Hello everybody,

I am currently working on a project in which I need to read some data from a glucometer. Until last week it was working fine, however I stopped receiving notifications from the glucometer. I started debugging and realize that an issue is happening when I am enabling the notifications: I write to the CCCD using sd_ble_gattc_write and get the error NRF_ERROR_BUSY. Problem is that I am never getting the event BLE_GATTC_EVT_WRITE_RSP, so I´m not getting any notifications either.

Does anyone know what could be happening?

I will gladly provide more information if necessary

Thanks in advance

Parents
  • Hi, 

    What SDK version are you using?

    Is this a custom board, or a DK ?

    If you read the sd_ble_gattc_write @note, you can read that a BLE_GATTC_EVT_WRITE_RSP event will be issued as soon as you are finished with the first write response. Do you add BLE_GATTC_EVT_WRITE_RSP case in the ble event handler? There is an example in this case. Do you update MTU at the same time? See this case

    You can call sd_ble_gattc_write() again when you receive that event.

    Regards,
    Amanda

  • Hello Amanda and thank you for your answer,

    - I am using a Development Kit with SDK version 17.0.2.
    - I do have a BLE_GATTC_EVT_WRITE_RSP case in the ble event handler . It goes to a function that I will post bellow.
    - I do not think I am updating the MTU at the same time

    static void txBufferProcess(void) {
    
      if (g_tx_index != g_tx_insert_index) {
        uint32_t err_code;
    
        if (g_tx_buffer[g_tx_index].type == READ_REQ) {
          err_code = sd_ble_gattc_read(g_tx_buffer[g_tx_index].conn_handle,
                                       g_tx_buffer[g_tx_index].req.read_handle, 0);
        } else {
          err_code = sd_ble_gattc_write(
              g_tx_buffer[g_tx_index].conn_handle,
              &g_tx_buffer[g_tx_index].req.write_req.gattc_params);
        }
        if (err_code == NRF_SUCCESS) {
          printf("\nSD Read/Write API returns Success..");
          g_tx_index++;
          g_tx_index &= TX_BUFFER_MASK;
        } else {
          printf("\nSD Read/Write API returns error. This message sending will be 
          attempted again..");
        }
      }
    }
    
    static void onWriteResponse(BLEGLSCollector_t *p_ble_gls_collector,
                                ble_evt_t const   *p_ble_evt) {
    
      // Check if the event if on the link for this instance
      if (p_ble_gls_collector->conn_handle != p_ble_evt->evt.gattc_evt.conn_handle) {
        return;
      }
      
      // Check if there is any message to be sent across to the peer and send it.
      txBufferProcess();
    
      printf("\nThis is the write response");
    
        //printf("GATTC status %x\n", p_ble_evt->evt.gattc_evt.gatt_status);
    
      if (p_ble_evt->evt.gattc_evt.gatt_status ==
          BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION) {
        printf("\nEnable notification failed.");
      }
    }

  • Hi, 

    Could you check this characteristic includes the write property and not just write without response? Note that you can check what propertise the characteristic has through the nRF Connect app. See the figures in this post

    -Amanda

  • Hello. I know that it sends a response because when it was working, I got one.

    Do you think it might be that another response, maybe a read response, that is blocking the write response? I do not have a case for BLE_GATTC_EVT_READ_RSP.

    Thank you

  • Hi, 

    From the documentation, "NRF_ERROR_BUSY: For write with the response, a procedure already in progress. Wait for a BLE_GATTC_EVT_WRITE_RSP event and retry."

    So it's strange that you do not get the BLE_GATTC_EVT_WRITE_RSP event.

    Could you provide a sniffer log? And maybe you can add some extra printing in your onWriteResponse function by adding a print on the first line. Something like this:

    static void onWriteResponse(BLEGLSCollector_t *p_ble_gls_collector,
    ble_evt_t const *p_ble_evt) {
    
    printf("\nThis is a write response...");

    -Amanda

  • Hello,

    I encountered this post and did what this person was suggesting (process the buffer for the write response and the read response as well). It is working now again. Hopefully it solves the problem for good.

    Thanks for your support Amanda :)

Reply Children
Related