Alarm issue with SLEEP_MODE_DEEP after WKP pin event

Hi all,

I have a Photon with FW v0.6.1-rc2. Here below is simple the code that it runs:

#include "application.h"

SYSTEM_MODE(MANUAL);

#define RELAY_ON_PIN D1
#define RELAY_OFF_PIN D0
#define RELAY_SENSE_PIN D2
#define LED_STATUS D6
#define RELAY_DELAY 30

#define DEEP_SLEEP_SECONDS 5
#define DELAY_TIME_MS 5000

void setup()
{
}

void switch_relay_on(void)
{
    pinMode(RELAY_ON_PIN, OUTPUT);
    digitalWrite(RELAY_ON_PIN, HIGH);
    delay(RELAY_DELAY);
    digitalWrite(RELAY_ON_PIN, LOW);
}

void switch_relay_off(void)
{
    pinMode(RELAY_OFF_PIN, OUTPUT);
    digitalWrite(RELAY_OFF_PIN, HIGH);
    delay(RELAY_DELAY);
    digitalWrite(RELAY_OFF_PIN, LOW);
}

void loop()
{
    pinMode(LED_STATUS, OUTPUT);
    digitalWrite(LED_STATUS, HIGH);

    delay(DELAY_TIME_MS);

    pinMode(RELAY_SENSE_PIN, INPUT);

    if (HIGH == digitalRead(RELAY_SENSE_PIN))
    {
        switch_relay_on();
    }
    else
    {
        switch_relay_off();
    }

    digitalWrite(LED_STATUS, LOW);

    System.sleep(SLEEP_MODE_DEEP, DEEP_SLEEP_SECONDS);
}

The application runs fine and the Photon wakes up at regular intervals as expected, but only as long as the WKP pin is low when the Photon enters in Standby mode following an external WKP event (WKP pin rising edge). In fact in such case if the WKP pin is high before the Photon enters the Standby mode then it will not be woken up any more by the internal RTC alarm.

There is an interesting Note in the STM32F205xx Reference Manual which states the following:

Note: An additional wakeup event is detected if the WKUP pin is enabled (by setting the EWUP bit) when the WKUP pin level is already high. (see PWR_CSR register description).

Is this condition handled by the system drivers ?

Here below a timing diagram showing the point (in red) when the issue occurs.

Ping @mdma, @BDub

Thanks for the report @embedded! I’ve confirmed some unwanted behavior (although a little different than you describe) and filed an issue here.

Instead of the issue being that WKP is HIGH when the device sleeps, I find the issue is when WKP is HIGH when the RTC alarm expires.

Workarounds:

  • Use System.sleep(SLEEP_MODE_DEEP);
  • Filter WKP input such that AC signal is passed, DC is blocked, to avoid being stuck HIGH. This won’t prevent all situations, but should lesson the occurrence of WKP being HIGH when the RTC alarm goes off.

Also not sure if this was you, but I accidentally duplicated the issue. There was another one just before mine:

That was me

Thank you for your feedback !

I hope this is a FW and not an HW issue. Unfortunately the listed workarounds are not viable when the WKP pin is connected to the output of a PIR sensor and it is also strictly required that the system automatically wakes up periodically to perform some tasks.

Why won't this work? Can't you put a capacitor between the sensor and the WKP pin to block the DC as BDub suggested?

1 Like

Well…I need to do some PCB rework which in reality I wanted to avoid :grin:

1 Like