Skip to content

rtc.write_datetime(dt_write) seems cannot write the seconds. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yyw04 opened this issue Sep 16, 2018 · 1 comment
Open

rtc.write_datetime(dt_write) seems cannot write the seconds. #3

yyw04 opened this issue Sep 16, 2018 · 1 comment

Comments

@yyw04
Copy link

yyw04 commented Sep 16, 2018

i use ds1302_set_utc to set the datetime, usually get the message:
unable to set RTC time

so i checked the code, found this clause cannot fullfill
-2 < (dt_write - dt_read).total_seconds() < +2

so after i call rtc.write_datetime(dt_write), then read time out
dt_read = rtc.read_datetime(), always get the seconds begin from 0.

@ThomasBouet
Copy link

I just know the basics in python but from toying with the size of the variable bytes_l in the function write_datetime I saw a few things.
So I am speaking about this

bytes_l = [0] * 9

If you multiplie by anything equals or below 6 you will experience index out of range exception.
With 7 or 8, the seconds seems to be saved (you trigger the if condition with the time difference between write and read).
With 9 you do not write the seconds.
With 10 you do not write the minutes and the seconds.
With 11 you do not write the hours, the minutes and the seconds.
With 12 you do not write the days, the hours, the minutes and the seconds.
With 13 you do not write the months, the days, the hours, the minutes and the seconds.
With 14 only the year is written.
With 15 and above the following is written "2000 0 0 0 0 0".

So by setting the multiplier to 7 or 8 you should trigger the if condition.

But maybe it creates other problems elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants