Hi,
The purpose of this is to have a software Power ON/OFF button, when I first start the firmware, it automatically goes OFF. Then after a long press on the button, it should turn ON and start advertising.
The first time everything works fine, device is connected to my laptop and communication is fine. But when I turn my device OFF and turn ON again (or reset), the device gets connected for about half a second and then throws a disconnect event with the following reason: BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION.
I noticed that when I remove the turn_off() function call, the problem disappears and I can connect and reconnect without problems.
What can cause this issue ? Am I doing something wrong ? if yes, what is the correct way to implement such a soft switch ON/OFF ?
I use SDK_15_3_0 and softdevice S132
(This is not the full firmware but merely the snippet I use for unit testing this functionality, if this unit test works fine the rest should also )
Thanks a lot
void turn_off(){
uint32_t err_code;
err_code = bsp_btn_ble_sleep_mode_prepare();
NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter;
}
int main(void)
{
wait_for_on_signal = true;
uint32_t err_code;
bool erase_bonds;
clock_initialization();
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
buttons_leds_init(&erase_bonds);
bsp_board_led_on(3); // Green LED OFF
scheduler_init();
app_timer_create(&m_first_long_press_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
first_long_press_timeout_handler);
app_timer_start(m_first_long_press_timer_id, FIRST_LONG_PRESS_INTERVAL, NULL);
if(nrf_gpio_pin_read(BUTTON_1)){
turn_off();
}
while(wait_for_on_signal){
app_sched_execute();
}
bsp_board_led_off(3);
my_app_timers_create();
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
advertising_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
advertising_start(erase_bonds);
my_app_timers_start();
for (;;)
{
idle_state_handle();
}
}