Config
- Using NRF52810 on a custom PCB with 32kHz + 32MHz crystals, very close to the reference schematic
- S112 with SDK 14.2.0 in SEGGER Embedded Studio V3.30
A button press from a sleeping state triggers an app_button interrupt which calls ble_advertising_start() followed by app_timer_start() and then nrf_gpio_pin_write() to turn on an LED. The timer ends after 50ms and turns off the LED. Advertising lasts 5 seconds.
Normal behaviour
This works almost every time as expected, a 50ms LED flash when the button is pressed and 5s of advertising.
Problem
The problem seems quite rare and I can't forcefully reproduce it because I don't yet understand how it's happening. Around 1 in 50 times (rough estimate) when pressing the button to wake from sleep, the LED will flash for a very short period (you have to hold it up to your eye to see it) and will keep doing short flashes on button presses until advertising stops 5s later. It seems that it will only get into this state when waking from sleep (4uA with 32kHz type sleep) and won't fall into this state by pressing the button if the device is already advertising.
In this short-lived state where you see very short LED flashes, the advertising seems to work properly but connection attempts fail. The system isn't resetting, all the data is still fine after recovering from this state. Interestingly, if I put the ble_advertising_start() line at the end instead of the start; more often than not, the LED will flash but advertising fails to start completely.
The problem is really quite hard to reproduce so I wouldn't recommend trying, I'm also unable to share my project. I'm just hoping that someone who knows more about the internals of the SDK might have a better idea of which direction to look to solve this.
- How can starting advertising cause an app_timer to finish way too early?
- Is this even related to advertising, or does app_timer get itself confused on its own?
- Might this be 32kHz crystal related?
Thanks for any suggestions in advance :)