I am evaluating the G80 (G80 dev board) for a project that will suit NETMF perfectly if I can reliably test a few aspects, one of them being able to put the chip to sleep and wake up on GPIO and serial data events.
I have pulled this low power example from the docs, but I am having trouble getting it to wake properly:
[ul] the CPU seems to go into DeepSleep fine
after waking, execution continues as expected but stops at the next Thread.Sleep() and halts here for 1 minute regardless of the sleep time entered.
Same behaviour happens when in debug, release or when I boot the board completely disconnected from VS
When connected to a VS session, it seems that any activity on the debug USB port (such as setting a breakpoint anywhere) causes the Sleep call to exit and the the program execution continues until Sleep is called again.
[/ul]
Here is some output from the serial port:
06/01/2011 00:00:01
06/01/2011 00:00:01
06/01/2011 00:00:01
going to sleep
wake up
06/01/2011 00:00:03
06/01/2011 00:01:03
06/01/2011 00:02:03
Is there something I’ve missed?
If the CPU can wakeup from multiple events, is there a way to check which event woke it up? Register access maybe?
Thank for the help - I’m new to NETMF and I have been waiting for a suitable project to come along to use it!
public class Program
{
static OutputPort LED1;
static OutputPort LED2;
static OutputPort LED3;
private readonly static InterruptPort _LDR0 = new InterruptPort(G80.Gpio.PE3, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
static bool EnableLowPower = false;
static int SleepCountDown = 10;
public static void Main()
{
Debug.Print(Resources.GetString(Resources.StringResources.String1));
LED1 = new OutputPort(GHI.Pins.G80.Gpio.PE14, true);
LED2 = new OutputPort(GHI.Pins.G80.Gpio.PE13, true);
LED3 = new OutputPort(GHI.Pins.G80.Gpio.PE11, true);
LED2.Write(EnableLowPower);
_LDR0.OnInterrupt += _LDR0_OnInterrupt;
while (true)
{
LED1.Write(!LED1.Read());
Thread.Sleep(100);
if(Enable[ul]LowPower)
SleepCountDown--;
if(SleepCountDown <= 0)
{
tempString = "going to sleep\n";
UART.Write(UTF8Encoding.UTF8.GetBytes(tempString), 0, tempString.Length);
LED1.Write(false);
SleepCountDown = 10;
LED3.Write(false);
PowerState.WakeupEvents = HardwareEvent.OEMReserved1 ;
PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1 );
tempString = "wake up\n";
UART.Write(UTF8Encoding.UTF8.GetBytes(tempString), 0, tempString.Length);
LED3.Write(true);
EnableLowPower = false;
}
}
}
static void _LDR0_OnInterrupt(uint data1, uint data2, DateTime time)
{
EnableLowPower = !EnableLowPower;
LED2.Write(EnableLowPower);
}