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
  • Hi Soma!

    Are you sure that you are in a connection and that the connection handle has been updated before initiating the disconnect?
    The error 0x3002 indicates that a invalid connection handle has been supplied.
    I tested this in the ble_app_uart example in SDK 11, and it seems to work fine.
    I executed the disconnection on a button push;

    bool check; 
    uint32_t err_code;
    	case BSP_EVENT_KEY_2: 
    	   check = softdevice_handler_isEnabled();
    	   if ((check == true) && (m_conn_handle != BLE_CONN_HANDLE_INVALID))
    	   {
    	      err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    	      APP_ERROR_CHECK(err_code);
    	   }
    	   break; 
    

    The sd_ble_gap_disconnect() call initiates the disconnection procedure, and its completion will be communicated to the application with a BLE_GAP_EVT_DISCONNECTED event. Your connection handle will most likely be set to invalid when the disconnection event is received.
    Take a look at this message sequence chart.

    When the disconnection event i received, the device will most likely start advertising again.
    You can see how this is handled in the ble_advertising.c file.
    The fact that the sd_ble_gap_adv_stop() returns error code 0x0008 (NRF_ERROR_INVALID_STATE) is most probably because your device is not in advertising state yet.

    Best regards,
    Joakim.

  • yeah i'm sure that the device is connected. I even tried with the nrf toolbox and nrf connect application.

Reply Children
No Data
Related