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

nRF51822 and S110 why does device wake from sleep and call main?

I am working with the nRF51822 chip and the S110 softdevice on a device that uses an accelerometer to wake up. Battery life is a concern, so we have developed the device so that it advertises with a timeout of 10 seconds when the device is shaken (triggering an accelerometer interrupt). We put the device to sleep using sd_app_evt_wait() when possible.

I have noticed that when the device wakes up after it has stopped advertising, it calls main again, and my global variables stored in RAM are set to zero. This behavior did not occur when we were continuously advertising (timeout value of 0).

Is there a way to prevent the device calling main again? Is the device entering a "deeper sleep"? I am worried that I will have to persist my global variables in flash.

Parents
  • monpetit - yes! good catch. I inherited this code from another developer, so forgive my oversight.

    I believe that the behavior I was seeing is because in ble_advertising.c, we were calling sd_power_system_off() when we set the BLE_ADV_EVT_IDLE advertising mode.

    So this raises another question - what is the correct method of halting advertising without calling sd_power_system_off()? I have tried calling sd_ble_gap_adv_stop(), but it returns with an error code of 0x08.

Reply
  • monpetit - yes! good catch. I inherited this code from another developer, so forgive my oversight.

    I believe that the behavior I was seeing is because in ble_advertising.c, we were calling sd_power_system_off() when we set the BLE_ADV_EVT_IDLE advertising mode.

    So this raises another question - what is the correct method of halting advertising without calling sd_power_system_off()? I have tried calling sd_ble_gap_adv_stop(), but it returns with an error code of 0x08.

Children
No Data
Related