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

sd_ble_gap_conn_param_update error 8

I have an application where my nrf52832 acts as a peripheral and I can connect to it without problems, but after some time like aprox 10 minutes when I try to connect to it again it doesn't accept the connection until it resets and then the cycle restarts.

I'm trying to debug this problem and the function "sd_ble_gap_conn_param_update" gives me "error 8 - Invalid state" following the previous pattern... Why? The connection parameters seems ok...

SD 3.0.0, sdk 12.2.

define MIN_CONN_INTERVAL MSEC_TO_UNITS(250, UNIT_1_25_MS)

define MAX_CONN_INTERVAL MSEC_TO_UNITS(350, UNIT_1_25_MS)

define SLAVE_LATENCY 0

define CONN_SUP_TIMEOUT MSEC_TO_UNITS(1500, UNIT_10_MS)

define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000,APP_TIMER_PRESCALER)

define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER)

define MAX_CONN_PARAMS_UPDATE_COUNT 3

Thank you!

Daniel.

  • You probably get the invalid state error because you are not in a connection. Add a check for the connection handle:

    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    

    To check if you are in a connection, or disregard the error code returned from the function.

  • Nope, inside ble_conn_params.c -> update_timeout_handler() I forced to check again the m_conn_handle but the error appears appears when the device is connected.

    static void update_timeout_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
    
        if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            // Check if we have reached the maximum number of attempts
            m_update_count++;
            if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
            {
                uint32_t err_code;
    
                // Parameters are not ok, send connection parameters update request.
                err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
                if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)&& (m_conn_handle != BLE_CONN_HANDLE_INVALID))
                {
                    m_conn_params_config.error_handler(err_code);///error here!
                }
            }
            else
    [...]
    
  • Ok, I thought you used the sd_ble_gap_conn_param_update(..) directly in your code and not the SDK library.

    I checked and the only time sd_ble_gap_conn_param_update(..) will return error NRF_ERROR_INVALID_STATE (0x8) is if the device is not in a connection. The only explanation I can think of as to why you get this error code is that the peer has disconnected, but the application has yet not gotten the disconnected event or have not executed the code that is to be run on disconnect (the event is pending because other interrupts at equal or higher level has to be executed first). So the SoftDevice knows that the connection is lost, but the application don't.

    I assume that you have not altered the SDK library code (ble_conn_params).

  • I'm using the SDK library. The only modification is the one that I posted here (the added condition on the 'if'). Now I'm trying to find the source of the error and I blocked the parameters update (I read on another post that this can be done safely) commenting those lines on the same file inside the function "conn_params_negotiation(void)"

    if (m_update_count == 0){ // First connection parameter update timeout_ticks = m_conn_params_config.first_conn_params_update_delay; }else{ timeout_ticks = m_conn_params_config.next_conn_params_update_delay; }

           /* err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)){
                m_conn_params_config.error_handler(err_code);
            }*/
    

    [...]

  • doing this the parameters update timer never starts and it works as "normaly" I can connect to it without problems the first times... The only change is that now I'm facing exactly the same behaviour but the error appears on another function "sd_ble_gatts_exchange_mtu_reply()" inside the "BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST" event, also with error 8...

Related