Open clodnut opened 3 weeks ago
Hi @clodnut! We appreciate you submitting your first issue for our open-source project. 🌟
Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙
Thanks for the report! Since you seem to have identified a fix, could you please submit a pull request? Thanks!
Describe the bug
ds1307_init() zeroes-out the "SECONDS" field of the time in the DS1307 device, corrupting the time.
Details
ds1307_init() correctly clears the DS1307's "Clock Halt" bit which will be set when power is first applied to the DS1307.
However, it does this by wiping out the entire DS1307_REG_SECONDS register, which unconditionally zeroes-out the "seconds" field of the time:
This operation should be a read/modify/write to clear only bit 7 ("CH") and only if that bit is set (so the time cannot change between read and write).
This would avoid corrupting the "seconds" field(s).
I suggest:
Tested informally and seems to work.