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.");
      }
    }

Reply
  • 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.");
      }
    }

Children
Related