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

Disconnect nrf51822 when the correct connection interval is not negotiated with the phone

Hi Sometimes the nrf the central does not accept my connection interval of 7.5ms. I want to disconnect nrf51822 when the correct connection interval is not negotiated with the phone.just want to know if the if statement at the end of the code is the correct way to do this

static void conn_params_init(void)
{
 uint32_t err_code;
 ble_conn_params_init_t cp_init;

 memset(&cp_init, 0, sizeof(cp_init));

 cp_init.p_conn_params = NULL;
 cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
cp_init.next_conn_params_update_delay = NEXT_CONN_PARAMS_UPDATE_DELAY;
cp_init.max_conn_params_update_count = MAX_CONN_PARAMS_UPDATE_COUNT;
cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
cp_init.disconnect_on_fail = true;
cp_init.evt_handler = on_conn_params_evt;
cp_init.error_handler = conn_params_error_handler;

err_code = ble_conn_params_init(&cp_init);


APP_ERROR_CHECK(err_code);
}

This is my conn_params_negotiation function. I believe the app_start_timer is called in the right position

static void conn_params_negotiation(void) {

// Start negotiation if the received connection parameters are not acceptable
if (!is_conn_params_ok(&m_current_conn_params))
{
    uint32_t err_code;
    uint32_t timeout_ticks;

    if (m_change_param)
    {
        // Notify the application that the procedure has failed
        if (m_conn_params_config.evt_handler != NULL)
        {
            ble_conn_params_evt_t evt;

            evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
            m_conn_params_config.evt_handler(&evt);
        }
    }
    else
    {
        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);
        }
    }
}
else
{
    // Notify the application that the procedure has succeded
    if (m_conn_params_config.evt_handler != NULL)
    {
        ble_conn_params_evt_t evt;

        evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
        m_conn_params_config.evt_handler(&evt);
    }
}
m_change_param = false;

}

This is my conn_params_change_conn_params

uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params) {

uint32_t err_code;

m_preferred_conn_params = *new_params;
// Set the connection params in stack
err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
if (err_code == NRF_SUCCESS)
{
    if (!is_conn_params_ok(&m_current_conn_params))
    {
        m_change_param = true;
        err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
        m_update_count = 1;
    }
    else
    {
        // Notify the application that the procedure has succeded
        if (m_conn_params_config.evt_handler != NULL)
        {
            ble_conn_params_evt_t evt;

            evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
            m_conn_params_config.evt_handler(&evt);
        }
        err_code = NRF_SUCCESS;
    }
}
return err_code;

}

Related