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

Cannot disconnect the device once it is connected

Hello guys,

I have problem, I activate the BLE and connect it to my tablet application until then nothing wrong happens. But when I use sd_ble_gap_disconnect() to disconnect, I got error_code 0x3002 which prevent me to disconnect.

what I do to disconnect:

check = softdevice_handler_isEnabled();
if (check == true && m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
	u32_err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
	m_conn_handle = BLE_CONN_HANDLE_INVALID;
    APP_ERROR_CHECK(u32_err_code); //err_code returned before check 0x3002
}
u32_err_code = sd_ble_gap_adv_stop();
APP_ERROR_CHECK(u32_err_code);  //err_code returned before check 0x0008

I use nrf52832, s132 softdevice with uart. I want to be disconnected and stop advertising, can any one please let me know how to correct this.

Thanks in advance for your time!

PS: The device is a peripheral one

Parents
  • Error 0x3002 means BLE_ERROR_INVALID_CONN_HANDLE, so it sounds like your validity check on m_conn_handle isn't working.

    That makes the if statement suspect. I'd first recommend adding brackets to your if statement to separate the two logical comparisons.

    if ((check == true) && (m_conn_handle != BLE_CONN_HANDLE_INVALID))
    

    This makes sure the compiler knows the order to make the comparison in.

    If that doesn't help, follow up on where m_conn_handle is last written, and post it here. Note that m_conn_handle can be invalid when it has other values than BLE_CONN_HANDLE_INVALID.

    For example, the connection has already been once broken due to a poor signal, and m_conn_handle was not updated.

Reply
  • Error 0x3002 means BLE_ERROR_INVALID_CONN_HANDLE, so it sounds like your validity check on m_conn_handle isn't working.

    That makes the if statement suspect. I'd first recommend adding brackets to your if statement to separate the two logical comparisons.

    if ((check == true) && (m_conn_handle != BLE_CONN_HANDLE_INVALID))
    

    This makes sure the compiler knows the order to make the comparison in.

    If that doesn't help, follow up on where m_conn_handle is last written, and post it here. Note that m_conn_handle can be invalid when it has other values than BLE_CONN_HANDLE_INVALID.

    For example, the connection has already been once broken due to a poor signal, and m_conn_handle was not updated.

Children
Related