Hi All,
Any one help me in doing this. I need to continously print the current date and time in DD/MM/YY and HH:MM:SS format. Iam using ARM LPC2378. I am not sure whether my RTC code is correct. Please confirm or suggest if there is something else I need to do. My code which is creating the problem goes as follows:
void RTCInit(void) { PCONP |= 0x0200; /* RTC Power Enabled */ RTC_CCR = 0x11; /* RTC Osci.Clock Enabled */ RTC_ILR |= 0x01; /* RTC Interrupt Enabled */ RTC_AMR |= 0xFF; /* Alarm Mask Register Disabled */ RTC_CIIR = 0x01; /* Every Second Interrupt Enabled */ RTC_CISS = 0x87; /* Sub Second Interrupt Disabled */ return; } void RTCSetDateTime(RTCDateTime DateTime) { RTC_SEC = DateTime.RTCSec; RTC_MIN = DateTime.RTCMin; RTC_HOUR = DateTime.RTCHour; RTC_DOM = DateTime.RTCMday; RTC_MONTH = DateTime.RTCMon; RTC_YEAR = DateTime.RTCYear; return; } RTCDateTime RTCGetDateTime(void) { RTCDateTime LocalDateTime; /* Store RTC date and time in st_LocalDateTime structure */ LocalDateTime.RTCSec = RTC_SEC; LocalDateTime.RTCMin = RTC_MIN; LocalDateTime.RTCHour = RTC_HOUR; LocalDateTime.RTCMday = RTC_DOM; LocalDateTime.RTCMon = RTC_MONTH; LocalDateTime.RTCYear = RTC_YEAR; return (LocalDateTime); }
In some other part of the code I am updating the structure variables to set the time initially. And when I do this I call RTCSetDateTime(initiallocaltime); as follows
{ ... ... /* Reset the counter which is resposible for Sec Timer increment in RTC */ RTC_CCR |= 0x03; /* CTC Reset in CCR */ RTC_ILR |= 0x05; /* RTC Sec Timer Counter Reset*/ /* Updation of RTC with Date & Time initially*/ RTCSetDateTime(initiallocaltime); RTC_CCR = RTC_OSC_SELECT; ... ... }
and finally Iam printing the time. Date and time is printed correctly for some time and later the it jumps above or below (some times in seconds/minutes and mostly in hours) and starts running from there.
Please let me know how can I avoid this problems with RTC and print the correct date and time continously eoth out any disturbances.
Thanks and Regards, Sravan Kumar M.
"I have one more doubt. what if RTC_SEC the register itself is giving a wrong value due to some reason. how can I correct RTC_SEC value?"
What reason?
Is the RTC_SEC any more likely to return a wrong value than any other register?
Sometimes you have to trust what your given - Otherwise you'll have to check every register on every access?!
But ... On a restart, you might want to check all date/time registers for validity and reset them if the value is obviously wrong; e.g., the RTC might be battery backed and the battery might be flat.