cancel
Showing results for 
Search instead for 
Did you mean: 

Reading RTC Value

sjackson
Associate II
Posted on February 27, 2007 at 18:24

Reading RTC Value

4 REPLIES 4
sjackson
Associate II
Posted on May 17, 2011 at 09:36

I am having problems reading the value of the RTC in my program. If I halt execution in the debugger, I can see that the time value is being updated. However when I try to read the current time, the data in the structs I pass to the read functions never changes.

Here is what I am doing after I initialize the RTC:

Code:

RTC_TIME *theTime;

RTC_DATE *theDate;

while(1)

{

RTC_GetTime(BCD, theTime);

RTC_GetDate(BCD, theDate);

}

When stopping the debugger, the values contained within theTime and theDate never change. Even if I let the program run freely for several seconds then halt it again, the values are unchanged.

What could be going wrong?

Thanks.

Posted on May 17, 2011 at 09:36

Hi SJackson,

if you use a pointer to a structure you MUST initialize it.

try something like

RTC_TIME theTime;

RTC_DATE theDate;

....

RTC_GetTime(BCD, &theTime);

RTC_GetDate(BCD, &theDate);

...

amira1
Associate II
Posted on May 17, 2011 at 09:36

Hi all,

The RTC_GetTime and the RTC_GetDate don't give the updated values of time and date.

However, The time register (TR) is updated automatically by the RTC. Hence, to obtain the current date and time in days, hours, minutes and seconds, you can read directly the TR.

Best regards,

mirou

gu48bz
Associate II
Posted on May 17, 2011 at 09:36

Hi Mirou,

Are you sure about that? I think you'll find that GetRTCTime reads from the TR register... for example:

void RTC_GetTime(u8 Format, RTC_TIME * Time)

{

Time->hours = (u8)((RTC->TR&0x003F0000)>>16);

Time->minutes = (u8)((RTC->TR&0x00007F00)>>8);

Time->seconds = (u8)(RTC->TR&0x7F);

Time->milliseconds =(u16)(RTC->MILR&0xFFF);

if (Format == BINARY)

{

Time->hours = BCD2ToBYTE(Time->hours);

Time->minutes = BCD2ToBYTE(Time->minutes);

Time->seconds = BCD2ToBYTE(Time->seconds);

Time->milliseconds = BCD3ToWORD(Time->milliseconds);

}

}

As pointed out early this issue is due to the author passing in an initialised ptr (hence HAL code is randomly writing into memory), rather than an address of a structure to populate.