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);		
}

  • SDK version: SDK 13.0

    Why the old SDK? Most recent SDK for the nrf52832 is 15.3 version.

    Your best bet is to hook up a debugger and check which one of the APP_ERROR_CHECK() triggers.

    My (wild) guess would be: Starting advertizing twice and thus getting error from ble_advertising_start() function.

  • Hi,

    Just wondering if you're on right way.. if your case assumes one session, for example, in 2-3 hours, it's ok. But if your device will trigger data exchange once per 5-10 minutes, it's better to maintain connection with high slave latency, because power consumed while negotiation will whittle away the gain got by disconnecting device.

  • 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 

  • Hi Dmitry:

    Thanks for your kind reply. 

    We are developing some special project, which have a insufficient power driving capability. So, the sampled signal quality will be sensitive to the BLE data transmission and even BLE advertising. That's why I want to turn off BLE data transmission and even BLE advertising in the data sampling. And after a specific time when there is enough samples ready for data transmission, the code start advertising and BLE transmission.

    Best

Related