This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC is creating problem in ARM LPC2378

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.

Parents
  • Strange that your new post doesn't contain the fixes that was suggested earlier, to handle a turnover of the seconds field - did you not think you needed it? And still lots of copying of full structures.

    You haven't showed us how you verify the contents of the hour field - how do you print the data? Can you really do one call to RTCSetDateTime() and directly after call RTCGetDateTime() and the hour field has ticked one step?

    Do you possibly involve a PC that is making use of any time zone so one of your printouts shows UTC time and one printout shows local time?

Reply
  • Strange that your new post doesn't contain the fixes that was suggested earlier, to handle a turnover of the seconds field - did you not think you needed it? And still lots of copying of full structures.

    You haven't showed us how you verify the contents of the hour field - how do you print the data? Can you really do one call to RTCSetDateTime() and directly after call RTCGetDateTime() and the hour field has ticked one step?

    Do you possibly involve a PC that is making use of any time zone so one of your printouts shows UTC time and one printout shows local time?

Children
  • Sir,
    I think that the fixes you mentioned previously are for rollover. Am I right? I believe that the problem is not with rollover.. Some how only the hours field is changing its value and continues time from there.. if it is rollover as you mentioned.. if the time is 12:59:59 it should show 13:59:59 and has to continue with 13:00:00 isn't it? But my time is continued with 13:59:59.. means from the next second it runs from 14:00:00.

    I am trying print the time continously in while(1) loop in the main().

    Thanks and Regards,
    Sravan Kumar M.

  • So you think that if you have never seen the problem with rollover, you will not need to implement such protection? How clever do would you say such a decision is?

    You still didn't respond to my other comments. How did you print the value you set the clock with?

    Have you also verified that you test with a minimum of code so you don't have other code that accidentally touches your data? And have you verified that your supply voltages are always peachy? Including the voltage on the VBAT pin?