RTC - Use NTP to rectify DS1307/DS3231 RTC
Preparation
- Ameba x 1
- DS1307/DS3231 RTC x 1
Example
In this example, we use NTP to rectify the time of DS1307/DS3231 RTC module.
The following libraries are required:
The following libraries are required:
DS1307 RTC library:
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/DS1307RTC-1.0.0.zip
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/DS1307RTC-1.0.0.zip
RTL8195 Wiring Diagram as follows:
RTL8710 Wiring Diagram as follows:
Open the sample code from “File” -> “Examples” -> “AmebaDS1307RTC” -> “SetTimeNtp”
In the sample code, please provide the ssid/password for WiFi connection. Then compile and upload the sample to Ameba and press reset button. You should see similar log in the Serial Monitor, which means the recification has completed:
Code Reference
After the WiFi connection is established, we use NTP to rectify the time of Time library:
setSyncProvider(getNtpTime);
Next, use the time value from Time library to setup the tmElements_t variable, and give the variable to RTC.write()
RTC.write(tm);
Finally, we read RTC time value in loop() every second.
Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved. Terms of Use