Hi,
I'm trying to write data to a characteristic. This is a BLE led driver. I can successfully send 5 writes and then it stucks. All the 5 sends succeed - I can see the led colors change.
The problem is - the BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE is never trigerred. I tried waiting for it to trigger before calling the next write. If I don't wait, this is the debug log:
00> <info> ble_scan: name filted matched 00> 00> <debug> ble_scan: Connecting 00> 00> <debug> ble_scan: Connection status: 0 00> 00> <debug> nrf_sdh_ble: BLE event: 0x10. 00> 00> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 32 bytes on connection 0x0. 00> 00> <debug> nrf_ble_gatt: Updating data length to 32 on connection 0x0. 00> 00> <debug> nrf_ble_gq: Registering connection handle: 0x0000 00> 00> <debug> ble<debug> ble_led_c: setting led color to: 255, 10, 0 00> 00> <debug> ble_led_c: setting led color to: 255, 15, 0 00> 00> <debug> ble_led_c: setting led color to: 255, 20, 0 00> 00> <debug> ble_led_c: setting led color to: 255, 25, 0 00> 00> <debug> ble_led_c: setting led color to: 255, 30, 0 00> 00> <debug> ble_led_c: setting led color to: 255, 35, 0 00> 00> <error> app: Failed sending data to LED service. Error 0x13. 00> 00> <error> app: ERROR 19 [NRF_ERROR_RESOURCES] at ..\..\..\main.c:2232 00> 00> PC at: 0x0003A307 00> 00> <error> app: End of error report
Here are some selected parts of my code. I've added delays to see if it changes anything:
do { err_code = ble_led_c_set_led_color(&m_led_c, led_rgb[i]); write_complete = false; if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("Failed sending data to LED service. Error 0x%x. ", err_code); APP_ERROR_CHECK(err_code); } nrf_delay_ms(500); //while(!write_complete); } while (err_code == NRF_ERROR_BUSY); ... uint32_t ble_led_c_set_led_color(ble_led_c_t * p_ble_led_c, uint8_t* rgb) { VERIFY_PARAM_NOT_NULL(p_ble_led_c); // NRF_LOG_DEBUG("Setting the LED's color. Handle = 0x%x, Connection Handle = 0x%x", // p_ble_led_c->peer_led_db.led_handle, // p_ble_led_c->conn_handle); uint8_t value[7] = {0x56, rgb[RED], rgb[GREEN], rgb[BLUE], 0x00, 0xF0, 0xAA}; NRF_LOG_DEBUG("setting led color to: %i, %i, %i", rgb[RED], rgb[GREEN], rgb[BLUE]); ble_gattc_write_params_t led_c_req; memset(&led_c_req, 0, sizeof(led_c_req)); led_c_req.len = sizeof(value); led_c_req.p_value = value; led_c_req.offset = 0; led_c_req.handle = p_ble_led_c->peer_led_db.led_handle; led_c_req.write_op = BLE_GATT_OP_WRITE_CMD; return sd_ble_gattc_write(p_ble_led_c->conn_handle, &led_c_req); /* nrf_ble_gq_req_t led_c_req; memset(&led_c_req, 0, sizeof(led_c_req)); led_c_req.type = NRF_BLE_GQ_REQ_GATTC_WRITE; led_c_req.error_handler.cb = gatt_error_handler; led_c_req.error_handler.p_ctx = p_ble_led_c; led_c_req.params.gattc_write.handle = p_ble_led_c->peer_led_db.led_handle; led_c_req.params.gattc_write.len = sizeof(value); led_c_req.params.gattc_write.offset = 0; led_c_req.params.gattc_write.p_value = value; led_c_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_CMD; led_c_req.params.gattc_write.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE; return nrf_ble_gq_item_add(p_ble_led_c->p_gatt_queue, &led_c_req, p_ble_led_c->conn_handle); */ }
Also an interesting part is that I get SD busy even before sending, see log:
00> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 32 bytes on connection 0x0. 00> 00> <debug> nrf_ble_gatt: Updating data length to 32 on connection 0x0. 00> 00> <debug> nrf_ble_gq: Registering connection handle: 0x0000 00> 00> <debug> ble_db_disc: Starting discovery of service with UUID 0xFFE5 on connection handle 0x0. 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Primary Services Discovery Request 00> 00> <debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted again later. 00> 00> <debug> nrf_ble_gq: Processing the request queue... 00> 00> <debug> nrf_ble_gq: GATTC Primary Service Discovery Request 00> 00> <debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted again later. 00> 00> <info> app: LED DRIVER connected 00>
What could cause this behaviour? I tried to find some information about this, or similar case but I did not suceed. I looked into the ble_app_uart_c example.
I'm on SDK 17.0.2 and SD 340, since I'm also using ANT+ in my project, however in the code above it should not intefere... I think :)
PS: if I use nrf_ble_gq_item_add to write data (commented piece of code in the ble_led_c_set_led_color function), then the log looks like this:
00> <debug> ble_scan: Connecting 00> 00> <debug> ble_scan: Connection status: 0 00> 00> <debug> nrf_sdh_ble: BLE event: 0x10. 00> 00> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 32 bytes on connection 0x0. 00> 00> <debug> nrf_ble_gatt: Updating data length to 32 on connection 0x0. 00> 00> <debug> nrf_ble_gq: Registering connection handle: 0x0000 00> 00> <debug> ble<debug> nrf_ble_gq: GATTC Primary Service Discovery Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0. 00> 00> <debug> nrf_ble_gatt: ATT MTU updated to 23 bytes on connection 0x0 (response). 00> 00> <debug> nrf_sdh_ble: BLE event: 0x24. 00> 00> <debug> nrf_sdh_ble: BLE event: 0x30. 00> 00> <debug> nrf_ble_gq: Processing the request queue... 00> 00> <debug> ble_db_disc: Found service UUID 0xFFE5. 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Characteristic Discovery Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0. 00> 00> <debug> nrf_sdh_ble: BLE event: 0x32. 00> 00> <debug> nrf_ble_gq: Processing the request queue... 00> 00> <debug> ble_db_disc: Discovery of service with UUID 0xFFE5 completed with success on connection handle 0x0. 00> 00> <info> app: LED_C event of type 1 00> 00> <info> app: LED service discovered. 00> 00> <debug> ble_led_c: setting led color to: 255, 0, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 5, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 10, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 15, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 20, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 25, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 30, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0. 00> 00> <debug> ble_led_c: setting led color to: 255, 35, 0 00> 00> <debug> nrf_ble_gq: Adding item to the request queue 00> 00> <debug> nrf_ble_gq: GATTC Write Request 00> 00> <error> nrf_ble_gq: SD GATT procedure (1) failed on connection handle 0 with error: 0x00000013. 00> 00> <debug> ble_led_c: A GATT Client error has occurred on conn_handle: 0X0 00> 00> <error> app: ERROR 19 [NRF_ERROR_RESOURCES] at ..\..\..\main.c:2189 00> 00> PC at: 0x000416C3 00> 00> <error> app: End of error report
Please help!