I need to enter Deep Sleep mode for about 15 seconds, then exit and run a scan for 3 seconds, then repeat this process. I also have 2 control pins set up to receive a button press. When the buttons are pressed, I also need to exit deep sleep mode. I have some audio that will play as well as a message sent out upon the buttons being pressed, so I can't be in Deep sleep for that.
I have the project running just fine without deep sleep enabled. Currently, i'm using a timer to count to a set number then run the scans, however this is draining the battery quickly.
The previous programmer working on this project has set up a WatchDog Timer with an interrupt.
Here he initializes the watchdog timer in main.c as seen below:
In addition to this, he has the LFCLK set to the external Watch Crystal Oscillator, which is what i'd want to use, according to everything i've read so far.
I suppose my idea was to enter low power mode and let the watchdog count to about 15 seconds, then use the interrupt to pull me out of low power, then scan. At the end of the scan, the function would put me back into low power mode, etc. There is one major problem with this - that I have no idea how to "count" time when the watchdog is operating. Further, I don't know if that's possible. As far as the buttons, I have absolutely no idea how to get me out of low power there.
Also, I ended up testing the "EnterLowPowerMode()" function from HERE. It tries to first go into deep sleep, if it fails, then it tries to enter sleep. I first tried the code with sleep only, and my device stops advertising, but the voltage draw is very low. On the other hand, when i tested Deep sleep, my device still advertised as well as had a higher voltage draw from the battery. I'm pretty flustered and lost... I am new to this, so please try to give me explanations if you can.
Thanks in advance for any help.
My BLE chip is part of a MESH system. When a message is received, the BLE chip goes from being a peripheral into a central role. The WDT is currently only being used to ensure that the BLE chip is in Central mode for a maximum of 4.5 seconds. So, I think I can replace this with a HFCLK timer. I see no reason to use the watchdog to be used for something like that - especially considering I can't have another Watchdog component with an interrupt ( I can't compile with 2 ).