This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF_ERROR_BUSY from characteristics discovery due to MTU exchange

My problem seems to be related to this unsolved question.

I've making a central application to connect to my peripheral but I'm having a hard time getting the service discovery to work. My central code is based on the central ble_app_uart_c. Here is a log of what happens:

 0> APP:INFO:ADVPKT: ed:60:1c:91:f4:38 -62dBm Bluetooth demo
 0> APP:INFO:Name match send connect_request.
 0> APP:INFO:Connected
 0> BLE_DB_DISC:DEBUG:Starting discovery of service with UUID 0xc001 on connection handle 0x0.
 0> APP:INFO:ERRdbds:0
 0> nrf_ble_gatt:DEBUG:Requesting to update ATT MTU to 158 bytes on connection 0x0.
 0> nrf_ble_gatt:DEBUG:sd_ble_gattc_exchange_mtu_request() on connection 0x0 returned busy, will retry.
 0> nrf_ble_gatt:DEBUG:Requesting to update data length to 162 on connection 0x0.
 0> nrf_ble_gatt:DEBUG:Requesting to update ATT MTU to 158 bytes on connection 0x0 (retry).
 0> BLE_DB_DISC:DEBUG:Found service UUID 0xc001.
 0> APP:INFO:db_disc_handler
 0> APP:INFO:EVT:1 UUID:11 Type:0
 0> APP:INFO:ERR:17
 0> nrf_ble_gatt:DEBUG:Data length updated to 27 on connection 0x0.
 0> nrf_ble_gatt:DEBUG:max_rx_octets: 27
 0> nrf_ble_gatt:DEBUG:max_tx_octets: 27
 0> nrf_ble_gatt:DEBUG:max_rx_time: 328
 0> nrf_ble_gatt:DEBUG:max_tx_time: 328
 0> nrf_ble_gatt:DEBUG:ATT MTU updated to 23 bytes on connection 0x0 (response).
 0> APP:INFO:ATT MTU exchange set to 23

What happens is that db_disc_handler() gets called which in turn calls the handler for my service, similar to what happens in ble_nus_c.h. The event that is passed is BLE_DB_DISCOVERY_ERROR and the error code in p_evt->params.err_code is 17 (NRF_ERROR_BUSY). The last thing logged before db_disc_handler is 'Found service UUID...'. Digging through the code of the discovery module I concluded the error must come from sd_ble_gattc_characteristics_discover().

I noticed some MTU exchange stuff in the log so I started messing with the MTU size in ble_stack_init(). I commented out the parts that set the ATT MTU size and updated the linker file. Now the service discovery works like it should but I get multiple errors like the one below here so I don't think this is a proper solution.

nrf_ble_gatt:ERROR:sd_ble_gattc_exchange_mtu_request() returned unexpected value 0x7.

I'm not sure what to change in order to get everything to work. I don't really care about the MTU size as I'm only making a demo and not dealing with large amounts of data. I included a zip of my code below. It's meant for the nRF52832 Dev Kit (PCA10040) using softdevice S130 and SDK 13.0.

Edit: Changing NRF_BLE_GATT_MAX_MTU_SIZE in sdk_config.h to 23 for both the peripheral and central has solve my issue as there is no MTU exchange anymore.

Related