Main Site Documentation

Snippet - G400 RTC get and set time using direct register access


#1

I just posted G400 RTC get and set time using direct register access on Codeshare. Feel free to discuss and make suggestions here.


#2

Thanks for sharing.
can you please explain what the bug is? that this fixes?


#3

@ Jay Jay in my device setup i have a total hang in a call to RealTimeClock.SetTime(xxx)
I am not sure if it is related to the problem described here: https://www.ghielectronics.com/community/forum/topic?id=14931


#4

@ RobvanSchelven - As in the other post, does your behavior change when using a day other than Sunday?


#5

@ James - No, its independent of the date, at least i tested with all dates of this current week.


#6

@ RobvanSchelven - Okay, we will test this case as well.


#7

@ James - Thanks.

Not related to the RealTimeClock but related to the clock (time) maintained in netmf is that on my raptor the clock runs one minute per hour to fast.


#8

@ RobvanSchelven - Thanks for posting this fix. I encountered this bug last night; thought I’d busted my Raptor at first!

There does appear to be a small bug in the posted code, however:

In SetTime, the conversion of the seconds value from datetime uses BCD2Byte rather than
Byte2Bcd.

was:


public static void SetTime(DateTime dateTime)
{
       UInt32 time = (UInt32)((UInt32)(BCD.Bcd2Byte((byte)dateTime.Second)) +
                                  (BCD.Byte2Bcd((byte)dateTime.Minute) << 8) + 
                                  (BCD.Byte2Bcd((byte)dateTime.Hour) << 16));

Changed:


 public static void SetTime(DateTime dateTime)
{
      UInt32 time = (UInt32)((UInt32)(BCD.Byte2Bcd((byte)dateTime.Second)) +
                                  (BCD.Byte2Bcd((byte)dateTime.Minute) << 8) + 
                                  (BCD.Byte2Bcd((byte)dateTime.Hour) << 16));


#9

@ Randyrtx - Thanks for the info. I will update the code.