AnsweredAssumed Answered

BF537 RTC cant write 2012 February 29

Question asked by PGaganoff on Feb 29, 2012
Latest reply on Mar 27, 2012 by SteveM

Hi!

Im using mentioned RTC on Blackfin. Today february 29, but im reading from it March 1.

Any tries to write right day are unsuccessful.

Here is my code to write RTC

if(( i = adi_rtc_GetDateTime( &DateTime1 )) != 0 )

{

  strcpy(str, "\r\nERROR: can't read Real Time Clock"); write(s, str, strlen(str)); continue;

}

else

{

//We got current date&time, now lets modify date

DateTime1.tm_mday = atoi(&par[0][0]);

if ( DateTime1.tm_mday <=0  || DateTime1.tm_mday > 31 )

{

  strcpy(str, "\r\nERROR: wrong parameter 'day'");

  write(s, str, strlen(str)); continue;

}

DateTime1.tm_mon =  atoi(&par[1][0]) - 1;

if ( DateTime1.tm_mon <0   || DateTime1.tm_mon > 11 ) 

{

  strcpy(str, "\r\nERROR: wrong parameter 'month'");

  write(s, str, strlen(str)); continue;

}

DateTime1.tm_year = atoi(&par[2][0]);

if ( DateTime1.tm_year < 80) DateTime1.tm_year+=100;

DateTime1.tm_year = DateTime1.tm_year-1;          

             

if(( i = adi_rtc_SetDateTime( &DateTime1 )) != 0 )

{

  strcpy(str, "\r\nERROR: can't write Real Time Clock");

  write(s, str, strlen(str)); continue;

}

Here code for reading

if(( i = adi_rtc_GetDateTime( &DateTime1 )) != 0 )

{

strcpy(str, "\r\nERROR: can't read Real Time Clock");

write(s, str, strlen(str)); continue;

}

else

{

   i = DateTime1.tm_year;

   i++;

   if (i>=100) i-=100;

   sprintf(str, "Current date (ddmmyy): %02d/%02d/%02d  (week day = %d)",     DateTime1.tm_mday, DateTime1.tm_mon+1, i, DateTime1.tm_wday+1);

   write(s, str, strlen(str));

}

So whats causing RTC not to notice that year have 29 days in February?

I dont really remember why am I increasing year number, but I it was for some purpose, after reading some examples of RTC using and docs on RTC. As I remember, day of week was calculated wrong without this adding.

Any help wanted.

Thanks in advance, Paul

Outcomes