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.

Parents
  • 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.

Reply
  • 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.

Children
Related