Skip to content

Remove verification check #20

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

Merged
merged 3 commits into from
Nov 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions adafruit_ds3231.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#. Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf

"""
import time
from adafruit_bus_device.i2c_device import I2CDevice
from adafruit_register import i2c_bit
from adafruit_register import i2c_bcd_alarm
Expand Down Expand Up @@ -96,14 +97,10 @@ class DS3231:
def __init__(self, i2c):
self.i2c_device = I2CDevice(i2c, 0x68)

# Try and verify this is the RTC we expect by checking the rate select
# control bits which are 1 on reset and shouldn't ever be changed.
buf = bytearray(2)
buf[0] = 0x0e
with self.i2c_device as i2c_device:
i2c_device.write_then_readinto(buf, buf, out_end=1, in_start=1)

if (buf[1] & 0b00011000) != 0b00011000:
# Try and verify this is the RTC we expect by checking change in secs
check = self.datetime_register.tm_sec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be stopped?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting question. It's possible, if the EOSC bit at 0x0E is set to 0 and the clock is on battery power only, then the clock would be stopped. I think maybe go back to the idea of a parameter being given to the constructor...verify_running=true? If true (default), the constructor verifies that the time is changing and so we have a running clock. If false, then the user clearly wants to be ok just having an item on 0x68.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. could be. hmmm. can be checked with OSF in status reg? but makes me question this general approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it all, use just the addr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so no "is it a DS3231" check? just "yep. something's at 0x68"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. address check covered by I2CDevice init.

time.sleep(1.1)
if self.datetime_register.tm_sec == check:
raise ValueError("Unable to find DS3231 at i2c address 0x68.")

@property
Expand Down