Panda II + Connect Shield: loosing time with restart

What do I need to do to keep the time of the real time clock using a Panda II with the Connect shield. the latter has a super cap. But even without disconnecting the USB power I loose the time after each restart / deploy. Why?

Voltage on the Super cap pin is ~ +3.0V

And you used realtimeclock class? :slight_smile:

I am using code from the NTP sample on code.tinyclr.com:

     
                    Utility.SetLocalTime(dateTime.AddMinutes(GmtOffset));
                    [b]RealTimeClock.SetTime(DateTime.Now);[/b]

...

       Debug.Print("System time before NTPTime : " + System.DateTime.Now.ToString());
        NTPTime("0.nl.pool.ntp.org", 60);
        Debug.Print("System time after NTPTime : " + System.DateTime.Now.ToString());

So the answer is hopefully yes! ???

Looks correct.

Can you try a simple app with only RTC to demonstrate the problem?

Are you using Panda or Panda II?


Utility.SetLocalTime(RealTimeClock.GetTime());

should do the trick. Of course, if the RTC has never been set, you’ll have to add some logic to test for that.

[edit] Also, the code you posted is out of order. It is not clear what your dateTime variable is set to before you use it. Not sure if you even need the first line. You should run the second line only after you have confirmed the NTP call worked. If I remember right (dubious assertion ;)) Nicolas3’s NTP function also sets the RTC, but best to check.

Essentially, it looks like you are setting the RTC from the System DateTime, which always initializes to 0 when you deploy/restart. This negates anything the NTP function did to set the RTC (if it even does) previous to the restart.

Changing it to


Debug.Print("real time clock before NTPTime : " + RealTimeClock.GetTime().ToString());
NTPTime("0.nl.pool.ntp.org", 60);
Debug.Print("real time clock after NTPTime : " + RealTimeClock.GetTime().ToString());

did the trick: the real time clock keeps the time, only the system time has changed.
Now I have to update the system time from the RTC and I should be done.

@ ransomhall
from the NTP example I only posted the part to show that I set the RTC at least once.