14
14
## Why the 10 bits Unix epoch time be used?
15
15
****Because I wanna connect to NTP server by ESP-8266.
16
16
****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进行更新。
17
24
*/
18
25
19
26
@@ -23,7 +30,7 @@ RTClock rtclock (RTCSEL_LSE); // initialise
23
30
int timezone = 8 ; // change to your timezone
24
31
time_t tt;
25
32
time_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
27
34
char weekday1[][7 ] = {" Sun" , " Mon" , " Tue" , " Wed" , " Thu" , " Fri" , " Sat" }; // 0,1,2,3,4,5,6
28
35
uint8_t dateread[11 ];
29
36
int globAlmCount = 0 ;
@@ -62,7 +69,8 @@ void setup()
62
69
lastSPECAlmCount = ~SPECAlmCount;
63
70
Serial.begin (115200 );
64
71
pinMode (LED_PIN, OUTPUT);
65
- tt = rtclock.makeTime (mtt);
72
+ tt = rtclock.makeTime (mtt);
73
+ rtclock.setTime (tt);
66
74
tt1 = tt;
67
75
rtclock.attachAlarmInterrupt (blink);// Call blink
68
76
rtclock.attachSecondsInterrupt (SecondCount);// Call SecondCount
@@ -79,7 +87,8 @@ void loop()
79
87
i = 0 ;
80
88
tt = (dateread[0 ] - ' 0' ) * 1000000000 + (dateread[1 ] - ' 0' ) * 100000000 + (dateread[2 ] - ' 0' ) * 10000000 + (dateread[3 ] - ' 0' ) * 1000000 + (dateread[4 ] - ' 0' ) * 100000 ;
81
89
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));
83
92
}
84
93
}
85
94
if (lastGlobAlmCount != globAlmCount | lastSPECAlmCount != SPECAlmCount ) {
@@ -111,20 +120,20 @@ void loop()
111
120
if (tt1 != tt & dispflag == true )
112
121
{
113
122
tt1 = tt;
114
- rtclock.breakTime (tt, mtt);
123
+ // rtclock.breakTime(tt, mtt);
115
124
Serial.print (" Date: " );
116
- Serial.print (mtt .day );
125
+ Serial.print (rtclock .day () );
117
126
Serial.print (" - " );
118
- Serial.print (mtt .month );
127
+ Serial.print (rtclock .month () );
119
128
Serial.print (" " );
120
- Serial.print (mtt .year + 1970 );
129
+ Serial.print (rtclock .year () + 1970 );
121
130
Serial.print (" " );
122
- Serial.print (weekday1[mtt .weekday ]);
131
+ Serial.print (weekday1[rtclock .weekday () ]);
123
132
Serial.print (" Time: " );
124
- Serial.print (mtt .hour );
133
+ Serial.print (rtclock .hour () );
125
134
Serial.print (" : " );
126
- Serial.print (mtt .minute );
135
+ Serial.print (rtclock .minute () );
127
136
Serial.print (" : " );
128
- Serial.println (mtt .second );
137
+ Serial.println (rtclock .second () );
129
138
}
130
139
}
0 commit comments