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

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

2 Likes

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

@ 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

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

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

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

@ 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.

@ 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));

1 Like

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