Hi All,
I want to use DFU to update the firmware from master to peripheral over BLE , both master and peripheral are nrf52840. My purpose is that the master sends a command to make the peripheral enter bootloader.Therefore I need enable indication and write 0x01 to peripheral. "nrf connect" can do it.
But the problem is that I don't kown if the indication is enable on peripheral.I referred to other answers but failed becuase I can't excuess sd_ble_gatts_value_get() and sd_ble_gatts_hvx() correctly, my programs are below.
//enable indication static uint32_t cccd_configure(ble_hrs_c_t * p_ble_hrs_c, bool enable) { NRF_LOG_INFO("Configuring CCCD. CCCD Handle = %x, Connection Handle = %x", p_ble_hrs_c->peer_hrs_db.hrm_cccd_handle, p_ble_hrs_c->conn_handle); nrf_ble_gq_req_t hrs_c_req; uint8_t cccd[BLE_CCCD_VALUE_LEN]; uint16_t cccd_val = enable ? BLE_GATT_HVX_INDICATION : 0; cccd[0] = LSB_16(cccd_val); cccd[1] = MSB_16(cccd_val); memset(&hrs_c_req, 0, sizeof(hrs_c_req)); hrs_c_req.type = NRF_BLE_GQ_REQ_GATTC_WRITE; hrs_c_req.error_handler.cb = gatt_error_handler; hrs_c_req.error_handler.p_ctx = p_ble_hrs_c; hrs_c_req.params.gattc_write.handle = p_ble_hrs_c->peer_hrs_db.hrm_cccd_handle; hrs_c_req.params.gattc_write.len = BLE_CCCD_VALUE_LEN; hrs_c_req.params.gattc_write.offset = 0; hrs_c_req.params.gattc_write.p_value = cccd; hrs_c_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ; hrs_c_req.params.gattc_write.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE; return nrf_ble_gq_item_add(p_ble_hrs_c->p_gatt_queue, &hrs_c_req, p_ble_hrs_c->conn_handle); }
ble_hrs_c_handles_assign
uint32_t ble_hrs_c_handles_assign(ble_hrs_c_t * p_ble_hrs_c, uint16_t conn_handle, const hrs_db_t * p_peer_hrs_handles) { VERIFY_PARAM_NOT_NULL(p_ble_hrs_c); p_ble_hrs_c->conn_handle = conn_handle; if (p_peer_hrs_handles != NULL) { //p_ble_hrs_c->peer_hrs_db = *p_peer_hrs_handles; NRF_LOG_INFO("In handles assign"); p_ble_hrs_c->peer_hrs_db.hrm_cccd_handle = p_peer_hrs_handles->hrm_cccd_handle; p_ble_hrs_c->peer_hrs_db.hrm_handle = p_peer_hrs_handles->hrm_handle; } return nrf_ble_gq_conn_handle_register(p_ble_hrs_c->p_gatt_queue, conn_handle); }
when find the service and characteristics
static void hrs_c_evt_handler(ble_hrs_c_t * p_hrs_c, ble_hrs_c_evt_t * p_hrs_c_evt) { ret_code_t err_code; bool is_indication_enabled = true; switch (p_hrs_c_evt->evt_type) { case BLE_HRS_C_EVT_DISCOVERY_COMPLETE: { NRF_LOG_INFO("dfu service discovered."); err_code = ble_hrs_c_handles_assign(p_hrs_c, p_hrs_c_evt->conn_handle, &p_hrs_c_evt->params.peer_db); APP_ERROR_CHECK(err_code); err_code = cccd_configure(p_hrs_c,true); APP_ERROR_CHECK(err_code); ble_gatts_value_t gatt_value; uint8_t cccd_value; gatt_value.len = 2; gatt_value.p_value = &cccd_value; gatt_value.offset = 0; err_code = sd_ble_gatts_value_get(p_hrs_c_evt->conn_handle, p_hrs_c->peer_hrs_db.hrm_cccd_handle, &gatt_value); APP_ERROR_CHECK(err_code); } break; default: break; } }
connection handle : 0, characteristics handle:0x16, cccd handle:0x17
sd_ble_gatts_value_get() returned error 5
I have no idea where is wrong , please give me some advice
Thanks,
Steven