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

NRF_ERROR_INVALID_STATE when calling ble_nus_data_send after connection is established

SDK version: nRF5_SDK_15.0.0_a53641a

Softdevice version: s132_nrf52_6.0.0_softdevice

PDK: PCA10040

  I am using the PCA10040 as a peripheral. When a connection is established with the central, I want to call ble_nus_data_send to send data to the central device.

I receive the following the following three ble events in the ble_evt_handler, once a connection is established:

BLE_GAP_EVT_CONNECTED (ble evt 10)
BLE_GAP_EVT_SEC_REQUEST (ble evt 24)
BLE_GATTC_EVT_EXCHANGE_MTU_RSP (ble evt 3a)

In the gatt_evt_handler I see the following event:

NRF_BLE_GATT_EVT_ATT_MTU_UPDATED

Once the NRF_BLE_GATT_EVT_ATT_MTU_UPDATED is received in the gatt_evt_handler, I find that I need to wait approx 2000ms before I can call ble_nus_data_send.

If I call ble_nus_data_send, for example 500ms after NRF_BLE_GATT_EVT_ATT_MTU_UPDATED, I get  NRF_ERROR_INVALID_STATE error response. If I wait for ~2000ms after NRF_BLE_GATT_EVT_ATT_MTU_UPDATED and then call  ble_nus_data_send I get a success response.

What could be the reason for this 2 second wait delay for the state change to occur after NRF_BLE_GATT_EVT_ATT_MTU_UPDATED? Is there any way to reduce this wait time? Also is there any way to know that the state change (any event indication) is complete instead of waiting a certain duration?

Parents Reply Children
Related