File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,34 +6,27 @@ static const char *ntpServer = "ntp.jst.mfeed.ad.jp"; // NTP server
66static const long gmtOffset_sec = 9 * 3600 ; // Time offset 9hr
77static const int daylightOffset_sec = 0 ; // No summer time
88
9- struct tm timeinfo;
10-
11- void getTimeFromNTP ()
12- {
13- // To get Time from NTP server
14- configTime (gmtOffset_sec, daylightOffset_sec, ntpServer);
15- while (!getLocalTime (&timeinfo))
16- {
17- delay (1000 );
18- }
19- }
20-
219void setNTP2RTC ()
2210{
11+ static struct tm timeinfo;
12+
2313 RTC_DateTypeDef RTC_DateStruct; // Data
2414 RTC_TimeTypeDef RTC_TimeStruct; // Time
25- // timeSet
26- getTimeFromNTP ( );
15+ // To get Time from NTP server
16+ configTime (gmtOffset_sec, daylightOffset_sec, ntpServer );
2717 getLocalTime (&timeinfo);
18+
2819 // read RTC
2920 M5.Rtc .GetTime (&RTC_TimeStruct);
3021 M5.Rtc .GetDate (&RTC_DateStruct);
22+
3123 // --- to over write date&time
3224 RTC_DateStruct.Year = timeinfo.tm_year + 1900 ;
3325 RTC_DateStruct.Month = timeinfo.tm_mon + 1 ;
3426 RTC_DateStruct.Date = timeinfo.tm_mday ;
3527 RTC_DateStruct.WeekDay = timeinfo.tm_wday ;
3628 M5.Rtc .SetDate (&RTC_DateStruct);
29+
3730 RTC_TimeStruct.Hours = timeinfo.tm_hour ;
3831 RTC_TimeStruct.Minutes = timeinfo.tm_min ;
3932 RTC_TimeStruct.Seconds = timeinfo.tm_sec ;
You can’t perform that action at this time.
0 commit comments