Core2 RTC challenge
-
Hello,
the Core2 contains an RTC component, the BM8563. The RTC library has so far only a few functions and uses e.g. the status register does not return.
I have now expanded the library to include these alarm functions:
void GetAlarm (RTC_AlarmTypeDef * RTC_AlarmStruct); void SetAlarm (RTC_AlarmTypeDef * RTC_AlarmStruct); void enableAlarm (); void disableAlarm (); void resetAlarm (); bool alarmActive ();
At start the functions worked very well, but now I can no longer use the BM8563 in normal way. At the start it always outputs the date 05.01.00 and a time from 00:07:00 to 00:07:07 and then starts again from 00:07:00. Other Arduino-libraries also show the same effect.
Resetting all registers from 00 to 0E to the value zero didn't help either, does anyone have an idea?
-
@sheepdog said in Core2 RTC challenge:
e.g. the status register does not return.
Hi @sheepDog
could you please elaborate what you mean by 'status register does not return'? How did you read it? I don't see a function in the RTC library to read a register so I assume you wrote your own function?
Reading the two RTC status registers works fine for me and they both return 0x00 which I guess is expected.
I've read the status registers with below function:
uint8_t RTC::ReadReg(uint8_t reg) { Wire1.beginTransmission(0x51); Wire1.write(reg); Wire1.endTransmission(); Wire1.requestFrom(0x51, 1); return Wire1.read(); } Serial.println(M5.Rtc.ReadReg(0x00)); Serial.println(M5.Rtc.ReadReg(0x01));
Maybe try to use a fresh copy of M5Core2 library (w/o your alarm code modifications) to verify your RTC behaves as expected?
Thanks
Felix -
Hello @felmue,
thanks for your answer. I meant that writing the value 0 in all status registers would not reset the BM8563!
I used a similar function for reading and writing:
void RTC::readBytes(uint8_t reg, uint8_t nbytes, uint8_t *data) { Wire1.beginTransmission(BM8563_ADDRESS); Wire1.write(reg); Wire1.endTransmission(); Wire1.requestFrom(BM8563_ADDRESS, nbytes); uint8_t index = 0; while( Wire1.available() ) data[index++] = Wire1.read(); } void RTC::writeBytes(uint8_t reg, uint8_t nbytes, uint8_t *data) { Wire1.beginTransmission(BM8563_ADDRESS); Wire1.write(reg); for (uint8_t i = 0; i < nbytes; i++) Wire1.write(data[i]); Wire1.endTransmission(); }
In the meantime I found an old fashion solution, because a fresh copy of M5Core2 library didn't not help. The problem was inside the registers of BM8563.
I disconnected the M5Core2 from USB and wait until the battery was empty. Now it's working again.
the problem was to factory reset the BM8563. -
Hi @sheepDog
hmm, are you saying that by writing something 'bad' into one (or more) of he RTC registers you were able to make it misbehave until it was 'factory reset' due to power loss?
I wonder if writing back a backup of all registers (from when RTC was running ok) would help getting a misbehaving RTC back on track w/o the need to let the battery run out?
Anyhow, I am glad you got it working again.
Thanks
Felix -
Hi @felmue,
yes, I believe that I wrote incorrect values in one (or more) of the RTC registers and that the BM8563 was factory or default reset due to the dead (!) battery.
Before I wrote back all registers with data sheet informations and so the RTC did not get back on track.
Thanks,
Uwe -
Hi Uwe
I did a test and removed the battery from my Core2 and let it sit for a couple of hours, but that did not reset RTC as it was still powered by the backup battery. How long did you wait for the battery to run out? Just curious to figure out what might have gone wrong with your RTC.
I did a second test and also removed the RTC backup battery and then read all RTC registers. Except for register 0x02 and 0x03 all came back with value 0x00, which I guess makes sense.
Thanks
Felix -
Hi @felmue,
I started M5Core2-Factory test, disconnected USB and go away. About 5 hours later I came back and tried to switch on M5Core. Nothing happened.
I connected USB, flashed the M5Core2 with the factory test program and everything worked fine.
At the last day I used my RTC-library with alarm functions and more and it worked continuously.
Cheers