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

BLE unable to connect

Hi, I am using the nRF connect app to test the BLE function on my code. I am able to scan the device and Service UUIDs just fine. However, when I click on the "connect" button, the status shows "connecting" but it never gets connected. 

In my main, I am calling the functions like this:

int main()
{
    clock_init();
    uart_config();
    twi_init();

    timers_init();
    buttons_leds_init(&erase_bonds);

    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();

    application_timers_start();
    advertising_start(&erase_bonds);
    
    while(1) {
        ...
    }
}

I have been trying to debug this but still isn't able to find cause to the problem. Any advice on where the issue might be?

Please let me know if more information is needed! Thank you!

Parents Reply Children
  • It is advertising in fast mode. I have the advertising_init() and advertising_init() shown below:

    static void advertising_init(void)
    {
        ret_code_t             err_code;
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance      = true;
        init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }
    
    
    static void advertising_start(void * p_erase_bonds)
    {
        bool erase_bonds = *(bool*)p_erase_bonds;
    
        if (erase_bonds)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
        }
        else
        {
            ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(err_code);
        }
    }
    

    The connection doesn't fail but it appearing to be connecting for a long time but it never gets connected. This is the log after I cancel the connection manually.

  • Hi,

    KCY said:
    The connection doesn't fail but it appearing to be connecting for a long time but it never gets connected.

    Do you get the BLE_GAP_EVT_CONNECTED event, and how do you handle ble connection events in the ble handler? A sniffer trace of the connection would clarify what really happens. Could you take a nrf sniffer trace of the connection and upload it here?

    regards

    Jared 

  • I am seeing a similar behavior when trying to connect to my peripheral device via nRF Connect on an Android phone.

    My set up: 
        SDK 15.3.0,
        SD version 6.1.1,
        nRF52832

Related