Skip to content

Commit fa7bcde

Browse files
committed
Update example for Chinese friends. timezone and filename error
1 parent 2d6abe6 commit fa7bcde

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

STM32F1/libraries/RTClock/examples/BlutPill-RTClock-test/BlutPill-RTClock-test.ino renamed to STM32F1/libraries/RTClock/examples/BluePill-RTClock-test/BluePill-RTClock-test.ino

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
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
2330
int timezone = 8; // change to your timezone
2431
time_t tt;
2532
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
2734
char weekday1[][7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // 0,1,2,3,4,5,6
2835
uint8_t dateread[11];
2936
int 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
}

STM32F1/libraries/RTClock/src/RTClock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RTClock {
7272
uint8_t second(time_t t) { breakTime(t, tmm); return tmm.second; }
7373
uint8_t isPM(time_t t) { return (hour(t)>=12); }
7474

75-
time_t TimeZone(time_t t, int TZ) { return ( t - (TZ * SECS_PER_HOUR)); } // usage: localtime = TimeZone(UnixTime, 8); // Beijing timezone = 8
75+
time_t TimeZone(time_t t, int TZ) { return ( t + (TZ * SECS_PER_HOUR)); } // usage: localtime = TimeZone(UnixTime, 8); // Beijing timezone = 8
7676

7777
void createAlarm(voidFuncPtr function, time_t alarm_time_t);
7878
void createAlarm(voidFuncPtr function, struct tm_t & alarm_tm);
@@ -95,4 +95,4 @@ class RTClock {
9595

9696

9797
#endif // _RTCLOCK_H_
98-
98+

0 commit comments

Comments
 (0)