Main Site Documentation

Raptor RTC problem


#1

Hi
I’ve recently bought a Raptor and am now trying to get to grips with C#. I’ve been slowly working my way through the tutorials and things are starting to become a little clearer - until tonight.

I appear to have a problem with the RTC where the time isn’t being set correctly. I’m using the RealTimeClock Example 2 tutorial but the output from the debugger is as follows:

Using mainboard GHI Electronics FEZRaptor version 1.0
Current Real-time Clock 01/01/1977 01:01:01
Time is not resonable
Current Real-time Clock 01/01/1977 01:01:01
New Real-time Clock 01/01/1977 01:01:01
The thread ‘’ (0x3) has exited with code 0 (0x0).

TinyBooter Version is 4.2.11.2
TinyCLR Version is 4.2.11.2

What have I done to break my new toy??? :-[


#2

I’ve managed to isolate the problem to the Flash Module. If I unplug the flash module the RTC can be set correctly - with it plugged in to any of the ‘S’ sockets the RTC cannot be set.


#3

can you show us the sample code you use to check/set the RTC when the issue occurs? Show us (screen shot) the Gadgeteer designer setup too.


#4

Very strange! Yes some code please.


#5

I was sure it was something I had done initially but if I disconnect the Flash module the code works fine.


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.Hardware;

namespace RTCTest
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
            DateTime DT;
            try
            {
                DT = RealTimeClock.GetTime();
                Debug.Print("Current Real-time Clock " + DT.ToString());
            }
            catch // If the time is not good due to powerloss or being a new system an exception will be thrown and a new time will need to be set
            {
                Debug.Print("The date was bad and caused a bad time");
                DT = new DateTime(2012, 1, 1, 1, 1, 1); // This will set a time for the Real-time Clock clock to 1:01:01 on 1/1/2012
                RealTimeClock.SetTime(DT); //This will set the hardware Real-time Clock to what is in DT
            }

            if (DT.Year < 2014)
            {
                Debug.Print("Time is not resonable");
            }

            Debug.Print("Current Real-time Clock " + RealTimeClock.GetTime().ToString());
            DT = new DateTime(2014, 2, 16, 7, 30, 0); // This will set the clock to 9:30:00 on 9/15/2011
            RealTimeClock.SetTime(DT); //This will set the hardware Real-time Clock to what is in DT
            Debug.Print("New Real-time Clock " + RealTimeClock.GetTime().ToString());
        }
    }
}



#6

@ Sprigo - I would like for you to try an experiment. With the flash module attached, can you change the date that is used in the program to a date that is not on a Sunday? But before changing the date can you erase the deployed application first then re deploy with a date that is not Sunday?


#7

I think you may have nailed it!

I changed the date to the 19th Feb 2014 and it works correctly. I then changed back to the 16th Feb and it’s back to 1/1/1977 It’s the same for the 23rd Feb 2014, another Sunday.


#8

@ Sprigo - It was a bug that we just discovered. The main processor uses 1~7 as the day codes while NetMF uses 0~6 as the day code and if 0 is used on the chip, the calendar does not get set correctly and the RTC does not function as supposed to. This is going in know issues, however, we have fixed it but we are waiting on how we will release this fix. If you get the datasheet, there may be a way you can manually set the RTC in the mean time.


#9

Great news in that you have isolated the problem. :clap:

It confused me as it was working one day (Sat) but not the next, now that I know what the problem is at least I can work around it for now.