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> BLE_DB_DISC:DEBUG:Starting discovery of service with UUID 0xc001 on connection handle 0x0.
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:EVT:1 UUID:11 Type:0
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.
This case deals with a similar problem, could you have a look at it and check if the latest update regarding configuration of the softdevice work in your case as well?
This didn't change anything for me, still the same issue.
Error code 0x7 is "Invalid parameter": Invalid Client RX MTU size supplied.
What is the client_rx_mtu value supplied to sd_ble_gattc_exchange_mtu_request()?
I use the GATT module so I'm not calling that function myself. I'm using the NRF_BLE_GATT_MAX_MTU_SIZE macro which is set to 158 for the central side and 23 on the peripheral. The central code has a call to nrf_ble_gatt_att_mtu_central_set with the above mentioned macro after initializing the GATT module. I also set the MTU in ble_stack_init().
Changing the macro on the peripheral side to 158 doesn't change anything. Trying to configure the MTU in ble_statck_init() for the peripheral gives error code 0x7.
Edit: Changing both to 23 seems to fix my issue as there is no MTU exchange happening now. Strange that I couldn't get it to work with 158.
I just tested the bare ble_app_uarrt_c example with ble_app_uart, and it seems to work fine out-of-the box. Could you test unmodified versions of those examples?