DateTime lost

Hi

The FEZ domino is a really cool hardware. I would like to use the RTC in battery operated mode.

I’m setting the datetime with
DateTime currDateTime = new DateTime(year, month, day, hour, min, sec);
Microsoft.SPOT.Hardware.Utility.SetLocalTime(currDateTime);

But after pressing the reset button or executing a MFDeploy Reboot CRL, the dateTime is always reset to 1/1/2009.

How can I make sure that I don’t loose the datetime?

What you are setting is the system clock and not the hardware RTC. The hardware RTC is set through a class that is not in current firmware yet so you can’t use it.

We have added this, along with many other new things, to the new firmware which will be available this week.

When new SDK is out in couple days, take a look at documentation and look for RTC. If you still can’t find it then let me know and I will give you an example.

I’m also trying to use the RTC. I have a 3.3V coin cell on VBAT, but still get clock resets on boot.

According to the e-book, DateTime.Now comes from the RTC. Is this correct?

Please see example code in documentation http://ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html

Gus… I am confused!

I am running the current GHI SDK and have been using the RealTimeClock class with success.

But, you say this class is not in the current firmware. Huh?

I never said it is not there! I am saying if it is not working then you are probably not using it correctly and should see the example in documentation.

RTC is there and it works as expected :wink:

I seem to have it working…

The following statement confused me. I must be misreading it.

MEA CULPA!

Just noticed the date on the original posting. :stuck_out_tongue:

LOL :slight_smile:

Yes that was long time ago but now RTC exists in current firmware.

Ok, thanks.

Someone should change the e-book, because it’s quite misleading:

"All GHI NETMF devices have a built in RTC. The RTC keep track of time and date. Even if
the system is off, the RTC will be running off a backup battery.

Here is an example that prints the current time and date to the debug output window."

(example follows which fetches the local time only, and does not access the RTC)

Yes that need to be fixed. This was correct long time ago but now it was changed.

I seem to behaving a similar problem to that described above. I mounted the 3 volt battery(+ to GND, - to VBAT), have checked all connections to make sure the voltage is getting thru correctly, but on each reboot (after removing power), the RTC is resetting to 01/01/1997. I have used the code in the example documentation exactly but it is still resetting.

Steps: Have this code in a button event:
RealTimeClock.SetTime(new DateTime(2010, 12, 27, 20, 55, 00, 00));
Utility.SetLocalTime(RealTimeClock.GetTime());

Next: Reboot (remove frm power and plug in again) and first lines in Main:

Utility.SetLocalTime(RealTimeClock.GetTime());
Debug.Print("RealTimeClock Date/Time: " + RealTimeClock.GetTime().ToString());
Debug.Print("Utility Date/Time: " + DateTime.Now.ToLocalTime());

And it will have reset again. Any ideas?
Thanks, Steve

OK, neermind, looks like I solved my own problem…went back and resoldered everything, doesn’t “look” or read on a voltmeter any different…but…apparently it is. Did I mention I was new to all this stuff? lol Thanks Anyway :slight_smile:

The important thing is that it is working :wink: Good job

I was having some trouble with the RTC on my Cerbuinos today. I think it’s kinda lame that I had to add a crystal since my Pandas came with those, but whatever. My problem was that, even with the battery and the crystal I was still losing time. Turns out it’s because of this line at the top of my program…

GHI.OSHW.Hardware.RTC.Initialize();

You need to call this to initialize the RTC, but only once with the batt and crystal in place otherwise it overwrites the time. This was the first line of my program. WRONG! My date kept getting cleared out. So I replaced my one line with these four…

DateTime rtcDate = GHI.OSHW.Hardware.RTC.GetTime();
if (rtcDate.Year < 2013)
{
GHI.OSHW.Hardware.RTC.Initialize();
}

This way my code only initializes the RTC (and clears the time) when needed. I wanted to use “if (rtcDate == DateTime.MinValue)” but apparently RTC.Initialize() uses some other date. I’d also suggest changing that, but what do I know…