Hi,
I'm having problems with proper softdevice reinitialization. What I'm trying to do is work out proper reinit solution - what I'm doing is enabling BLE_stack and all the other things in main.c and start advertising for 10 seconds. After 10 secons I'm calling sd_softdevice_disable() and after next 10 seconds I want to enable softdevice again. I'm using timer based at 1 second interval and counting up to 10 and 20 for Softdevice disable/enable. My problem is that I can re-enable softdevice and start advertising - that works fine, but when I try to add service_init() and all the other my BLE stack falls apart and I'm getting errors.
Please could you provide me proper way to reinitialize softdevice with all the gap/gatt functions? I would really appreciate that. I'm including piece of code that I use for softdevice enable/disable.
Just to be clear: I use internal rc oscillator with the following config:
nrf_clock_lf_cfg_t const clock_lf_cfg =
{
.source = NRF_CLOCK_LF_SRC_RC,
.rc_ctiv = 16,
.rc_temp_ctiv = 2,
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
};
uint8_t *ptr;
uint8_t softdevicex=1; //softdevice active at the beggining.
void timer_timeout_handler(void * p_context) //EVENT TRIGGERED EVERY 1 S.
{
toggle++; //just for counting up, every 1 second that increments
if(toggle>10 && softdevicex==1)
{
sd_softdevice_disable(); //disabling softdevice
softdevicex = 0;
if(sd_softdevice_is_enabled(ptr))
{
NRF_LOG_INFO("SoftDevice Enabled.");
}
else NRF_LOG_INFO("SoftDevice Disabled.");
}
if(softdevicex==1) //if softdevice is enabled then update characteristics
{
if(toggle%2==0) //FUNCTIONS JUST FOR DATA UPDATING FOR CHARACTERISTIC
temperature = 70;
else temperature = 90;
our_temperature_characteristic_update(&m_our_service, &temperature);
NRF_LOG_INFO("Characteristics updated.");
}
if(toggle>20 && softdevicex==0)
{
uint32_t err_code;
uint32_t new_ram=0;
err_code = sd_softdevice_enable(NRF_SDH_CLOCK_LF_RC_CTIV, app_error_fault_handler);
APP_ERROR_CHECK(err_code);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &new_ram);
APP_ERROR_CHECK(err_code);
err_code = nrf_sdh_ble_enable(&new_ram);
APP_ERROR_CHECK(err_code);
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
peer_manager_init();
advertising_start(erase_Bondx); //advertising start
softdevicex=1; //softdevice started indication
NRF_LOG_INFO("SoftDevice Re-enabled");
toggle=0; //erase counter value
}
}
THANK YOU IN ADVANCE