Internal RTC Nucleo F767ZI
Revision 1:12b099f1e8da, committed 2019-09-16
- Comitter:
- shivanandgowdakr
- Date:
- Mon Sep 16 13:42:47 2019 +0000
- Parent:
- 0:d8084da95aff
- Commit message:
- Internal RTC STM32 Simplified
Changed in this revision
RTC.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d8084da95aff -r 12b099f1e8da RTC.cpp --- a/RTC.cpp Wed Jun 06 06:54:18 2018 +0000 +++ b/RTC.cpp Mon Sep 16 13:42:47 2019 +0000 @@ -34,23 +34,64 @@ { int ret=0; struct tm curt; - - ret = Date_Time_Setting(curt,tstring); - - if(ret == 1) { - wait(1); - - // printf(" DATE-TIME SET SUCCESS "); - printf("Date Time Set succesfully\r\n"); + int index = 0; + + uint8_t date, month, hours, minutes, seconds; + uint16_t year; - } else { - - printf("Date Time Set Failure \r\n"); + char* token = strtok(tstring, "/ :"); + while (token != NULL) + { + index++; + if(index == 1) + { + date = atoi(token); + } + else if(index == 2) + { + month = atoi(token); + } + else if(index == 3) + { + year = atoi(token); + } + else if(index == 4) + { + hours = atoi(token); + } + else if(index == 5) + { + minutes = atoi(token); + } + else if(index == 6) + { + seconds = atoi(token); + } + + printf(" %d %s\n", index, token); + token = strtok(NULL, "/ :"); + } + curt.tm_mday = date; + curt.tm_mon = month - 1; + curt.tm_year = year -1900 ; + + curt.tm_hour = hours; + curt.tm_min = minutes; + curt.tm_sec = seconds; + + time_t epoch = mktime(&curt); + + if (epoch == (time_t) -1) + { + error("Error in clock setting\n"); + // Stop here } - wait(2); - // Clear_LCD(); - + else + { + set_time(epoch); + printf("time is Set: \r\n"); + } return ret; } @@ -112,7 +153,7 @@ tm * curr_tm; time(&curr_time); curr_tm = localtime(&curr_time); - strftime(date_string,10,"%Y%m%d",curr_tm); + strftime(date_string,10,"%Y/%m/%d ",curr_tm); } @@ -123,7 +164,7 @@ tm * curr_tm; time(&curr_time); curr_tm = localtime(&curr_time); - strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm); + strftime(DTSTRING,20,"%Y/%m/%d %H:%M:%S",curr_tm); // printf("Time is : %s",DTSTRING); } \ No newline at end of file