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

BLE disconnection

Hi,

I'm using NRF52840, and my application connects with BLE mobile application. After a minute, connection is lost.

I tried to find which functions called sd_ble_gap_disconnect, but I didn't find.

I think the reason may be the min and max connection interval. What are the recommended values?

Thanks!

  • I think the reason may be the min and max connection interval. What are the recommended values?

     That may in fact be the case. What does your log from the nRF52840 say?

    Perhaps you can add this line to your BLE_GAP_EVT_DISCONNECTED event in the ble_evt_handler()

    NRF_LOG_INFO("disconnect reason %d", p_ble_evt->evt.gap_evt.params.disconnected.reason);

    As you may or may not know, it is the central (typically the phone) that decides the connection parameters. If this is not within the desired connection parameters of the peripheral, it can request new connection parameters, but they may be declined. Then the peripheral can choose whether to accept these connection parameters, or to disconnect. 

    Basically it will try to update the connection interval 3 times (by default), and then, based on disconnect_on_fail it will either disconnect, or stay connected:

    static void update_timeout_handler(void * p_context)
    {
        uint32_t                     conn_handle = (uint32_t)p_context;
        ble_conn_params_instance_t * p_instance  = instance_get(conn_handle);
    
        if (p_instance != NULL)
        {
            // Check if we have reached the maximum number of attempts
            if (p_instance->update_count < m_conn_params_config.max_conn_params_update_count)
            {
                bool update_sent = send_update_request(conn_handle, &p_instance->preferred_conn_params);
                if (update_sent)
                {
                    p_instance->update_count++;
                }
            }
            else
            {
                p_instance->update_count = 0;
    
                // Negotiation failed, disconnect automatically if this has been configured
                if (m_conn_params_config.disconnect_on_fail)
                {
                    ret_code_t err_code;
    
                    err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
                    ...

    The default value of disconnect_on_fail depends on what SDK version you are using. In 15.3.0 it looks like it is set to false by default, but that may vary from example to example. 

    So what does your log say? And what is your disconnect_on_fail? 

    And by the way, what is your conn_interval min and max setting? Try setting it to 7.5 and 30 ms. That should cover the connection interval of most phones.

    Best regards,

    Edvin

  • Hi Edvin!

    The disconnection reason code is 19 (terminated by user).

    In addition, it doesn't seem that timeout handler has something to do with that.

    I'm using SDK 14.2.

    I tried different min and max connections invertals, including 75. and 30 - it's still don't work.

    Any other ideas?

    Thanks!

  • So your cp_init.disconnect_on_fail = false; in conn_params_init()?

    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             = false;
        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);
    }

    The nRF is the peripheral in the connection, right?

    Does your log say anything else? Can you please try to enable debug logging:

    set NRF_LOG_DEFAULT_LEVEL to 4 in sdk_config.h.

    What does the log say?

    Best regards,

    Edvin

  • Yes, p_init.disconnect_on_fail = false.

    The log doesn't say nothing, only that there was a disconnection - also when NRF_LOG_DEFAULT_LEVEL set to 4.

  • Ok. Does this only happen to this particular application? Or does it happen with all the examples from the SDK?

    Can you try to do a sniffer trace?

    I suggest you take a look at the nRF Sniffer.

Related