RTC Not Correct

My RTC is showing a value of about 13,000. Here is the body of the code:

struct tm t;
unsigned long time;

void getTime() {

        time = read_rtc();
        printf("RTC: %d", time);

  		mktm(&t, time);

  		printf("%2d/%02d/%4d %02d:%02d:%02d

", t.tm_mon, t.tm_mday,
t.tm_year + 1900 , t.tm_hour, t.tm_min, t.tm_sec);

It seems pretty basic, just somehow my RTC is messed up. I know it can be set and everything but that doesnt seem to be the cure im looking for. I am pretty new to Rabbit, any suggestions are welcome, Thanks!


Check the sample code that comes with DC for examples of how to use the RTC. If you don’t have battery backup connected the RTC will contain random data each time you power up the system. I was recently working on the same thing and each time I powered it up it would show a date sometime around 1980. The data the RTC holds is the number of seconds elapsed since 1/1/1980 so your figure of 13000 could be OK. Once I got the battery backup connected and set it properly, it was fine. ( But you must set all the fields. I left out the day of the week as it was not relevent to me but the RTC does not set properly if you leave out any fields.) Watch out for the fact that some of the time functions use SECTIMER. SECTIMER is an interrupt driven internal counter. It is synchronised with the RTC each time the system is reset. Provided interrupts are not blocked, they should stay in synch. I mostly rely on sectimer but read the RTC every hour in case they have drifted.