Sleep Wake Up Issue

I am trying to put an STM32F401 running NETMF 4.4 to sleep and wake up from an interrupt such as a button press. I am able to put the device to sleep fine but it wakes up on its own after 50 seconds (and not at all when the interrupts are triggered). If the device is in deep sleep, it does not automatically wake up. No RTC crystal is installed. The code is deployed in Release mode and running on battery power (no VS or MFDeploy attached). Any suggestions would be appreciated. Here is my test code:

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;

namespace Sleep_Test
{
    public class Program
    {
        private static InterruptPort Button1;
        private static bool Button1Flag;
        private static STU7066U display = new STU7066U();

        private static void Button1_Triggered(uint data1, uint data2, DateTime date)
        {
        Button1Flag = true;
        }

        public static void Main()
        {
            Thread.Sleep(1000);
            display.initialize();
            display.Clear();
            display.Print("Sleeping");

            Button1 = new InterruptPort(Pin.PB0, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            Button1.EnableInterrupt();
            Button1.OnInterrupt += new NativeEventHandler(Button1_Triggered);
            Button1.EnableInterrupt();

            PowerState.WakeupEvents |= HardwareEvent.OEMReserved1;
            PowerState.Sleep(SleepLevel.Sleep, HardwareEvent.OEMReserved1);

            display.Clear();
            display.Print("Awake!");
        }
    }
}

Update: It wakes from Sleep instantly on interrupt if HardwareEvent.GeneralPurpose is set instead of OEMReserved1. It is still not waking from DeepSleep still.

using System;
using System.Threading;
using Microsoft.SPOT.Hardware;
using SmartSensor;

namespace SmartSensorTest
{
public class Program
{
private static SmartSensor.Hardware.UserLed _led;
private static InterruptPort _key;
public static void Main()
{
_key = new InterruptPort(STM32.Pin.PA4, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
_key.OnInterrupt += key_OnInterrupt;
_led = new Hardware.UserLed();
_led.BlinkUserLed();
Thread.Sleep(Timeout.Infinite);
}

    static void key_OnInterrupt(uint data1, uint data2, DateTime time)
    {
        _led.BlinkUserLed(5,50);
        int n = 500000;

        while (n > 0) n--;

        Thread.Sleep(5000);
        PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.GeneralPurpose);
    }
}

}

1 Like

Thank you I think switching to HardwareEvent.GeneralPurpose fixed it.

…also it seems glitch filter cannot be set to true if in DeepSleep otherwise it won’t wake up.

@Justin I am still having issues. With HardwareEvent.GeneralPurpose and glitch filter disabled, after putting to Sleep it wakes up on its own after 1 minute or if my button interrupt is fired before 1 minute. It automatically wakes up every 1 minute on the dot if there is no interrupt fire before. In Deep Sleep it does not seem to wake itself up in this case.

Hard to say without seeing all of your set up.

So i ran a test with the following Molecules

Oxygen running NETMF 4.4
Lithium - Battery support
Boron - Button for waking Oxygen
Nitrogen - Buzzer

This setup will happily sit for hours and will only wake when Boron is pressed.

While sitting with a Thread.Sleep it consumes ~9ma
While running at full speed it consumes ~27.6ma
While in deep sleep its consumes ~1.9ma

Possible points of difference to you:
Boron does have a pull up resistor.
Oxygen does have a RTC

So…as labelled on the tin - it does work.

using System;
using System.Threading;
using Microsoft.SPOT.Hardware;

namespace PowerTest
{
    public class Program
    {
        private static InterruptPort _key;
        static OutputPort _led = new OutputPort((Cpu.Pin)16, false);
        private static PWM _nitrogen;
        public static void Main()
        {
            _nitrogen = new PWM((Cpu.PWMChannel)14, 261, 0.5, false);
            _key = new InterruptPort((Cpu.Pin)0, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            _key.OnInterrupt += key_OnInterrupt;

            Beep();
            _led.Write(true);
            Thread.Sleep(2000);
            _led.Write(false);
            Beep();
            Thread.Sleep(Timeout.Infinite);
        }
        static void key_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            for (int i = 0; i < 4; i++)
            {
                Beep();
                _led.Write(!_led.Read());
            }
            int n = 500000;

            while (n > 0) n--;

            Thread.Sleep(2000);
            PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.GeneralPurpose);
        }
        static void Beep()
        {
            _nitrogen.Start();
            Thread.Sleep(100);
            _nitrogen.Stop();
        }
    }
}