ds3231 RTC only keeps time, not date after power off
bambino69
Posts: 126
in Propeller 2
I've been using JonnyMac's driver(jm_ds3231.spin2 ) to access the clock.
I've tried the wr_calendar method used in his demo, and I've used the set_calendar method.
It will give me back the date, but after a power cycle only the time gets remembered!
Anyone else run into this?
Comments
I just fired my up that hasn't been used since and it's only 10 minutes slow.
Temp 22, Date: Sun Jan 16 15:38:09 2022
Mike
I've got another. Just putting off installing another in my enclosure.
I originally bought a 5 pack of these. I installed another yesterday, never opened before, and it does the same thing. Keeps time just fine, but zero's the date after reset. I must have bought something different from everyone else.
Anyway, I can finish my project without date. Would have been nice to have though!
Hi
Can you share your code?
Dave
Yes, should have some time to clean it up later today.
The data says
On the first application of power (VCC) or when a valid I2C address is written to the part (VBAT), the time and date registers are reset to 01/01/00 01 00:00:00 (DD/MM/YY DOW HH:MM:SS).
To preserve the battery, the first time VBAT is applied to the device, the oscillator will not start up until VCC exceeds VPF, or until a valid I2C address is written to the part. Typical oscillator startup time is less than one second. Approximately 2 seconds after VCC is applied, or a valid I2C address is written, the device makes a temperature measurement and applies the calculated correction to the oscillator. Once the oscillator is running, it continues to run as long as a valid power source is available (VCC or VBAT), and the device continues to measure the temperature and correct the oscillator frequency every 64 seconds.
Another sanity check, would be to disable the i2c to the RTC during a Prop power cycle, and check if anything changes.
If that is always stable then, the Prop must be causing the reset.
Here is the code, mine is actually using the LCD, but i figured PST would be easier. This on does the same thing.
I've noticed now that the only time i can display the date is after initialize_rtc is called. Once I comment that out and F10 again I can no longer see the date.
So now I don't think it's writing the register at all!
@jmg Give me a minute to digest that and I'll try it.
@jmg
By disable I2c, do you mean Hardware or software.
A jumper in the SCL line would isolate it.
Thanks, I'll try that tomorrow.
But I really don't think I'm writing to the registers at all.
I'm just reading back the same values I placed in initialize.
I could test that theory by writing initialize with local variables.
Anyway, goodnight for now.
Silly suggestion:
Write the date. Write the time to 11:58pm. Leave it all powered up for five minutes or so. Read the time - should be 12:03am or something. Read back the date - should have incremented. If it didn't, well! Seeya tomorrow (in more ways than one! S.
Confirmed I'm not reading from the clock.
I set the date, in initialize, by using local variables(per Scroungre's idea) , and assigned my birthday to the global variables that the calendar read method should have overridden with the date flashed by the local variables. What came back was my birthday.
So it didn't perform a read of the date programmed........true.
Didn't write the date programmed.........assumed.
I inspected the chip on the board, It does say ds3231sn.
Well, if you give us the pins your using we can send you a bin file you can load that will display the data off the chip.
Mike
pin 2 for data and pin 3 for clock
I set the time and date into the DS3231 so that it would roll-over in about 15 minutes. I turned off the power and went for my morning walk. An hour later I turned it back on and the time and date read correctly -- the day changed, too.
I changed my pins to match your setup and have attached my archive. The first time you run you need to uncomment initialize_rtc() to set the clock. After the program is downloaded with F10, open PST, enable it, and press a key. You should get something like this:
The next time you run the program be sure to comment out initialize_rtc() so that you don't overwrite the clock after your power-down period.
Hope this works.
Mike
Thank you JonnyMac,
Worked straight out of the box. I copied all the files over and shazam!
One of my files is obviously corrupt. So I'm going thru my library folder deleting files tonight.
@iseries
I've only ever loaded binary files with the WX module, I opened it and clicked Load Ram, opened PST. Not sure what was supposed to happen.
Hopefully problem solved, but would like to know what you meant. Would like to see a complete dump of the chip.
The code should have just got the date and time and displayed it just to make sure the clock module was working and not defective.
Mike