Main Site Documentation

RTC Raptor WakeUpInterrupt does not fire


#1

Hi:
I would like to use the RTC with the FEZ Raptor and I cannot get the syntax right. The code below compiles and executes, but the device never goes to sleep, nor does the interrupt fire. Any suggestions are greatly appreciated.
The debug shows:
Using mainboard GHI Electronics FEZRaptor version 1.0
Program Started
Before hibernate…01/04/2014 00:00:00
After hibernate…01/04/2014 00:00:00

Running 4.2


Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
' needed for RTC
Imports Microsoft.SPOT.Hardware
Imports Microsoft.SPOT
Imports System
Imports GHI.Premium.Hardware
Imports GHI.Premium.Hardware.LowLevel

Namespace GadgeteerApp1
    Partial Public Class Program

        Public Sub ProgramStarted()
            Debug.Print("Program Started")

            For i As Integer = 0 To 10
                Gadgeteer.Program.Mainboard.SetDebugLED(False)
                Thread.Sleep(200)
                Gadgeteer.Program.Mainboard.SetDebugLED(True)
                Thread.Sleep(200)
            Next

            Dim timestart As New DateTime(2014, 1, 3)
            RealTimeClock.SetTime(timestart)

            RealTimeClock.SetAlarm(RealTimeClock.GetTime().AddSeconds(10))
            Dim LDR As New InterruptPort(Cpu.Pin.GPIO_Pin0, True, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow)

            AddHandler LDR.OnInterrupt, AddressOf LDR_OnInterrupt
            Debug.Print("Before hibernate..." & RealTimeClock.GetTime.ToLocalTime.ToString)
            Power.Hibernate(Power.WakeUpInterrupt.RTCAlarm)
            Debug.Print("After hibernate..." & RealTimeClock.GetTime.ToLocalTime.ToString)
        End Sub

        Private Sub LDR_OnInterrupt(data1 As UInteger, data2 As UInteger, time As Date)
            Gadgeteer.Program.Mainboard.SetDebugLED(True)
            Debug.Print("After interrupt..." & RealTimeClock.GetTime.ToLocalTime.ToString)

        End Sub

    End Class
End NamespaceImports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
' needed for RTC
Imports Microsoft.SPOT.Hardware
Imports Microsoft.SPOT
Imports System
Imports GHI.Premium.Hardware
Imports GHI.Premium.Hardware.LowLevel

Namespace GadgeteerApp1
    Partial Public Class Program

        Public Sub ProgramStarted()
            Debug.Print("Program Started")

            For i As Integer = 0 To 10
                Gadgeteer.Program.Mainboard.SetDebugLED(False)
                Thread.Sleep(200)
                Gadgeteer.Program.Mainboard.SetDebugLED(True)
                Thread.Sleep(200)
            Next

            Dim timestart As New DateTime(2014, 1, 3)
            RealTimeClock.SetTime(timestart)

            RealTimeClock.SetAlarm(RealTimeClock.GetTime().AddSeconds(10))
            Dim LDR As New InterruptPort(Cpu.Pin.GPIO_Pin0, True, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow)

            AddHandler LDR.OnInterrupt, AddressOf LDR_OnInterrupt
            Debug.Print("Before hibernate..." & RealTimeClock.GetTime.ToLocalTime.ToString)
            Power.Hibernate(Power.WakeUpInterrupt.RTCAlarm)
            Debug.Print("After hibernate..." & RealTimeClock.GetTime.ToLocalTime.ToString)
        End Sub

        Private Sub LDR_OnInterrupt(data1 As UInteger, data2 As UInteger, time As Date)
            Gadgeteer.Program.Mainboard.SetDebugLED(True)
            Debug.Print("After interrupt..." & RealTimeClock.GetTime.ToLocalTime.ToString)

        End Sub

    End Class
End Namespace

Versions used:
Attaching deployed file.
Assembly: GTM.GHIElectronics.Display_HD44780 (4.2.102.0) Attaching deployed file.
Assembly: Microsoft.VisualBasic (1.0.0.0) Attaching deployed file.
Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.UsbClientDP (4.2.102.0) Attaching deployed file.
Assembly: GadgeteerApp1 (1.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.2.102.0) Attaching deployed file.
Assembly: GHI.Premium.IO (4.2.11.1) Attaching deployed file.
Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.
Assembly: GHI.Premium.Hardware (4.2.11.1) Attaching deployed file.
Assembly: GHI.Premium.System (4.2.11.1) Resolving.


#2

I tried this in C#, pretty much straight from https://www.ghielectronics.com/docs/141/low-power but still no luck. Here is the code I used in C# which may be easier for you sharpies to read:
I call this version The Endless Winter as spring never comes.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Hardware;
using GHI.Premium.Hardware.LowLevel;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp2
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {

            Debug.Print("Program Started");
            //setup the interrupt pin
            InterruptPort LDR = new InterruptPort((Cpu.Pin)0, false,
                                       Port.ResistorMode.PullUp,
                                       Port.InterruptMode.InterruptEdgeLow);
            LDR.OnInterrupt += new NativeEventHandler(LDR_OnInterrupt);
            Debug.Print("winter is upon us...");

            while (true)
            {
                Thread.Sleep(3000);//blink LED for 3 seconds
                // sleep
                Debug.Print("must still be winter...");
                Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);
                //we get here when we wakeup
            }
        }
        static void LDR_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print("spring must be here!!!");

        }
    }
}

#3

For your VB code, you are using RTC alarm which is not currently implemented. In your C# code, your interrupt is on pin 0 which is PA0/COM2 TX, not one of the loader pins. PA0 is Pin 4 on socket 4, if you want to give it a try for the interrupt wake up.


#4

@ rockybooth -

should add LDR.EnableInterrupt(), I think

https://www.ghielectronics.com/community/forum/topic?id=14842


#5

@ Dat - thanks, I had that for a while and then dropped it
@ John - thanks, I did not realize that the RTC alarm and low power options did not currently work, even though the methods are there.
Perhaps adding this information to the “Known Issues” section of the FEZ Raptor documentation page would be helpful to others.