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