Hi @peekay123, @satishgn @ScruffR & @kennethlimcp .
I have the wakeup by A0 (WKUP_PIN) in Deep Sleep kind of working!!! It is a little flaky but is clearly exiting DEEP SLEEP immediately on the WKUP_Pin rising. The key to making it work was to replace spark.sleep() function with a modified copy my_sleep() and the only change in that function being was I swapped out the Spark function Enter_STANDBY_Mode(); with the ST function PWR_EnterSTANDBYMode(); What needs to be resolved ie a little flaky is it seem not exit deep sleep properly by the timer (I must not be setting it up properly. Any ideas please let me know.
Oh there is an extremely good chance that some of register settings etc before sleep are not needed or somewhat wrong. I have to play with that some more.
@satishgn Where can I get some detail on what exactly Enter_STANDBY_Mode() does and a comparison with ST’s function?
\#include "stm32f10x.h"
SYSTEM_MODE(MANUAL);
void setup()
{
pinMode(A0, INPUT); //I have a 10k pull down
}
void loop()
{
switch some leds here
PWR_WakeUpPinCmd(DISABLE);
delay(100);
PWR_ClearFlag(PWR_FLAG_SB);
delay(100);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
PWR->CR |= 0x00000100;
PWR_WakeUpPinCmd(ENABLE);
my_sleep(SLEEP_MODE_DEEP, sleep_delay);
}
void my_sleep(Spark_Sleep_TypeDef sleepMode, long seconds)
{
/* Set the RTC Alarm */
RTC_SetAlarm(RTC_GetCounter() + (uint32_t)seconds);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
switch(sleepMode)
{
case SLEEP_MODE_WLAN:
WiFi.off();
break;
case SLEEP_MODE_DEEP:
blink_led(RED,20,FASTLED); //take out later to save battery
PWR_EnterSTANDBYMode();
blink_led(GREEN,20,FASTLED); //take out later to save battery
break;
}
}