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.

  • 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.

  • I'm not aware of your purpose, but isn't it sufficient to comment out sd_power_system_off() in your code? Is the advertising still on going after timeout?

  • No - advertising continues if I comment out that line in sleep_mode_enter()

  • That's strange, my example has stopped advertising.

  • I discovered the issue. My device is asleep most of the time and wakes up for events. The adv timeout event was waking up the chip and we were restarting advertising manually in our application code. Thank you very much for your help and time - I apologize that it ended up being an oversight on my part.

1 2