1414 ## Why the 10 bits Unix epoch time be used?
1515****Because I wanna connect to NTP server by ESP-8266.
1616****in the <NTPClient.h> library. getNtpTime() will return this 10 bits Unix epoch time.
17+ *
18+ * 嗨!朋友们, 这是一个STM32F10x系列的RTC应用的例子,希望对你的编码有所帮助
19+ * 这个程序基于https://github.com/rogerclarkmelbourne/Arduino_STM32 , 感谢所有贡献者的付出。
20+ * 程序测试了 F10x系列RTC 的 几种中断, 并通过LED和串口进行表达。
21+ * RTClock 使用 UTC 作为时间标准, 你可以从https://www.epochconverter.com/ 获得 Unix epoch time数值
22+ * 并通过串口进行设置, 当然你也可以略微修改一下串口接收处理方法,直接从串口接收日期形式。如 2017-9-13-10:30:00,
23+ * 另外一个方法是通过ESP8266获取NTP网络时间,并定期发送给F10x进行更新。
1724*/
1825
1926
@@ -23,7 +30,7 @@ RTClock rtclock (RTCSEL_LSE); // initialise
2330int timezone = 8 ; // change to your timezone
2431time_t tt;
2532time_t tt1;
26- tm_t mtt = { 47 , 9 , 13 , 3 , 1 , 22 , 30 , 30 }; // init time 47+1970 = 2017 Unix epoch Time counted from 00:00:00 1 Jan 1970
33+ tm_t mtt = { 47 , 9 , 13 , 3 , 11 , 22 , 30 , 30 }; // init time 47+1970 = 2017 Unix epoch Time counted from 00:00:00 1 Jan 1970
2734char weekday1[][7 ] = {" Sun" , " Mon" , " Tue" , " Wed" , " Thu" , " Fri" , " Sat" }; // 0,1,2,3,4,5,6
2835uint8_t dateread[11 ];
2936int globAlmCount = 0 ;
@@ -62,7 +69,8 @@ void setup()
6269 lastSPECAlmCount = ~SPECAlmCount;
6370 Serial.begin (115200 );
6471 pinMode (LED_PIN, OUTPUT);
65- tt = rtclock.makeTime (mtt);
72+ tt = rtclock.makeTime (mtt);
73+ rtclock.setTime (tt);
6674 tt1 = tt;
6775 rtclock.attachAlarmInterrupt (blink);// Call blink
6876 rtclock.attachSecondsInterrupt (SecondCount);// Call SecondCount
@@ -79,7 +87,8 @@ void loop()
7987 i = 0 ;
8088 tt = (dateread[0 ] - ' 0' ) * 1000000000 + (dateread[1 ] - ' 0' ) * 100000000 + (dateread[2 ] - ' 0' ) * 10000000 + (dateread[3 ] - ' 0' ) * 1000000 + (dateread[4 ] - ' 0' ) * 100000 ;
8189 tt += (dateread[5 ] - ' 0' ) * 10000 + (dateread[6 ] - ' 0' ) * 1000 + (dateread[7 ] - ' 0' ) * 100 + (dateread[8 ] - ' 0' ) * 10 + (dateread[9 ] - ' 0' );
82- tt = rtclock.TimeZone (tt, timezone); // adjust to your local date
90+ rtclock.TimeZone (tt, timezone); // adjust to your local date
91+ rtclock.setTime (rtclock.TimeZone (tt, timezone));
8392 }
8493 }
8594 if (lastGlobAlmCount != globAlmCount | lastSPECAlmCount != SPECAlmCount ) {
@@ -111,20 +120,20 @@ void loop()
111120 if (tt1 != tt & dispflag == true )
112121 {
113122 tt1 = tt;
114- rtclock.breakTime (tt, mtt);
123+ // rtclock.breakTime(tt, mtt);
115124 Serial.print (" Date: " );
116- Serial.print (mtt .day );
125+ Serial.print (rtclock .day () );
117126 Serial.print (" - " );
118- Serial.print (mtt .month );
127+ Serial.print (rtclock .month () );
119128 Serial.print (" " );
120- Serial.print (mtt .year + 1970 );
129+ Serial.print (rtclock .year () + 1970 );
121130 Serial.print (" " );
122- Serial.print (weekday1[mtt .weekday ]);
131+ Serial.print (weekday1[rtclock .weekday () ]);
123132 Serial.print (" Time: " );
124- Serial.print (mtt .hour );
133+ Serial.print (rtclock .hour () );
125134 Serial.print (" : " );
126- Serial.print (mtt .minute );
135+ Serial.print (rtclock .minute () );
127136 Serial.print (" : " );
128- Serial.println (mtt .second );
137+ Serial.println (rtclock .second () );
129138 }
130139}
0 commit comments