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

BLE connecting and disconnecting reset program

Hi:

SDK version: SDK 13.0

MCU: nrf52832

For the purpose of saving power, the peripheral disconnect the BLE connection in the program when there is no data transmission, and  the peripheral trigger to start advertising and build BLE connection when there is enough data for transmission. The code for disconnection and advertising is list below. 

The problem is, the code can trigger the first advertising/ble-connection and send data successfully to the central device, and after that it looks the device also successfully disconnect  from central (because BLE_GAP_EVT_DISCONNECTED is triggered.). But when the device trigger the second time advertising, it reset the main program. 

What's the possible reason for this? I search a lot similar cases on this website, but can not find solution for this.  

Thanks

static void ble_disconnect()
{
	uint32_t err_code;

	if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
	{
			err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
			if (err_code != NRF_ERROR_INVALID_STATE)
			{
					APP_ERROR_CHECK(err_code);
			}
	}

	err_code = sd_ble_gap_adv_stop();
	if (err_code != NRF_ERROR_INVALID_STATE)
	{
			APP_ERROR_CHECK(err_code);
	}
	
}

static void advertising_start()
{

       ret_code_t err_code, ret;
       err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
			 APP_ERROR_CHECK(err_code);		
}

Parents Reply Children
  • Hi Turbo:

    Thanks for your prompt reply. 

    It's just because this project was started 2 years ago, using SDK13.0. We just base on that for to continue the project for convenience. 

    In my code, after advertising_start(), the ble_nus_string_send() is called to transfer data out. 

    If I add nrf_delay_ms(800) between advertising_start() and  ble_nus_string_send(), the program will not be reseted. At least for a long time. 

    Do you know what's the reason for this? why I need a Delay before ble_nus_string_send().

    Thanks

    Wei 

Related