Hi all,
There is something really weird with my RTC.
I try to get the NTP time over WiFi, and then set the RTC with that time. Connecting the WiFi and getting the NTP time works flawless, the time shows correct, but then something goes wrong, and I can't figure out what. I tried it with the standard M5.Rtc structs, and now with the BM8563 library, but the result is the same: the time looks something like 13:00:00, and the hours (the 13 in this case) tick like seconds. The minutes and the seconds stay 00. The hours tick every second +1, sometimes until 19, sometimes until 35, ... and then restart from 00.
This is my code:
#include <I2C_BM8563.h>
#include <M5Core2.h>
#include <WiFi.h>
#include <NTPClient.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
#define BM8563_I2C_SDA 21
#define BM8563_I2C_SCL 22
I2C_BM8563 rtc(I2C_BM8563_DEFAULT_ADDRESS, Wire1);
const char *ssid = "mySSID";
const char *password = "myPassword";
//RTC_TimeTypeDef RTCtime;
int hour;
int minute;
int second;
void setup() {
M5.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
Wire1.begin(BM8563_I2C_SDA, BM8563_I2C_SCL);
rtc.begin();
M5.Lcd.setTextSize(1);
M5.Lcd.print("Connecting");
while ( WiFi.status() != WL_CONNECTED ) {
delay (500);
M5.Lcd.print(".");
}
timeClient.begin();
delay (1000);
timeClient.update();
hour = timeClient.getHours();
minute = timeClient.getMinutes();
second = timeClient.getSeconds();
M5.Lcd.print("Got time ");
M5.Lcd.print(hour);
M5.Lcd.print(":");
M5.Lcd.print(minute);
M5.Lcd.print(":");
M5.Lcd.println(second);
I2C_BM8563_TimeTypeDef timeStruct;
timeStruct.hours = hour;
timeStruct.minutes = minute;
timeStruct.seconds = second;
rtc.setTime(&timeStruct);
}
void loop() {
I2C_BM8563_TimeTypeDef timeStruct;
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(40,40);
rtc.getTime(&timeStruct);
M5.Lcd.printf("Time: %02d:%02d:%02d\n",timeStruct.hours, timeStruct.minutes, timeStruct.seconds);
delay(1000);
}
Any help is greatly appreciated ...