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

sd_ble_gap_disconnect error

Hello,

I have read a lot posts which has the same title unfortunately I am still unable to solve my problem. I am using pca10028, s110, SDK 6. Code is based on BLE_app_uart exapmle. This is my main function:

int main(void)
{
    timers_init();    	
	gpio_config();
	ble_stack_init();
	gap_params_init(); 		/*Generic Access Profile lowest layer of BlueTotth stack*/
	services_init();   		/*Add services*/
	advertising_init();		/*Advertising congif*/
	conn_params_init();   /*connection param config*/
	sec_params_init();    /*security param config*/
	/*BlueTooth done*/
	advertising_start();  
	
	while(1)
			{  
		 
				 if( m_conn_handle != BLE_CONN_HANDLE_INVALID ) // BLE is connected. Do service routine.
					{

						while (ble_tx_complete != 1)						
						{
							nrf_gpio_pin_write(GPIO_TOGGLE_CHECK_EVENT, 0);
							sprintf(send_string,"TEST");
							ble_nus_send_string(&m_nus,send_string,5);
						}												
						
						err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
							 if (err_code != NRF_SUCCESS)
								 {
								 return err_code;
								 }

		                        }
                power_manage();     	
               }
}

When I use break point at return err_code; I get result err_code = 0x00000008. NRF_UART does not show that it was disconnected to board. I do not know how to proceed further. Could anyone suggest what should I do next?

Thank you in advance.

  • I have tried this approach:

    {
              if (ble_tx_complete == 1)						
     {
    	err_code = sd_ble_gap_disconnect(m_conn_handle, 
             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    		 if (err_code != NRF_SUCCESS)
    			 {
    			  return err_code;
    			 }
    	 }
    }
    

    Application does not show it was disconnected to board. Debugging still get err_code =0x00000008 which led to hard fault handler.

  • Most likely, your application tries to call sd_ble_gap_disconnect() multiple times before m_conn_handle = BLE_CONN_HANDLE_INVALID is set, after ble_tx_complete = 1 is set. You should set the breakpoint on the if (err_code != NRF_SUCCESS) check. When you set the breakpoint on return err_code;, you will only break when a non-success error code is received. Can you try to set a flag after calling disconnect, to avoid calling this multiple times? What do you mean by "Application does not show it was disconnected to board"? Only that it does not print disconnect to UART? If you get a hardfault from calling disconnect function multiple times, the application will not continue.

  • Hello, Jorgen. Thank you for coming in help. Before I have read your comment I have tried various things to solve it and came across this question once again: devzone.nordicsemi.com/.../ Joris Roussel proposed solution by inserting m_conn_handle = BLE_CONN_HANDLE_INVALID; after sd_ble_gap_disconnect(). While debugging it like this I have not received error.

    Now I understand why placing a break point makes no sense. Break point at statement if (err_code != NRF_SUCCESS)shows that m_conn_handle is 0x0000 which is not equal to BLE_CONN_HANDLE_INVALID (0xFFFF).

    It's my unskillfulnes fault by saying that NRF_UART application does not show. It is unnecessery information.

    I would like to hear from you if setting m_conn_handle = BLE_CONN_HANDLE_INVALID after sd_ble_gap_disconnect() is correct solution.

  • Yes, you can set m_conn_handle = BLE_CONN_HANDLE_INVALID after calling sd_ble_gap_disconnect(). By default this is set in on_ble_evt() handler, when a BLE_GAP_EVT_DISCONNECTED event is received, but this event might come after your code has had time to call sd_ble_gap_disconnect() multiple times. By setting it right after starting diconnect procedure, you make sure disconnect function is not called again.

Related