Skip to content

Commit 4e90dca

Browse files
committed
change verification check
1 parent ed71b40 commit 4e90dca

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

adafruit_ds3231.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#. Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
5555
5656
"""
57+
import time
5758
from adafruit_bus_device.i2c_device import I2CDevice
5859
from adafruit_register import i2c_bit
5960
from adafruit_register import i2c_bcd_alarm
@@ -96,14 +97,10 @@ class DS3231:
9697
def __init__(self, i2c):
9798
self.i2c_device = I2CDevice(i2c, 0x68)
9899

99-
# Try and verify this is the RTC we expect by checking the rate select
100-
# control bits which are 1 on reset and shouldn't ever be changed.
101-
buf = bytearray(2)
102-
buf[0] = 0x0e
103-
with self.i2c_device as i2c_device:
104-
i2c_device.write_then_readinto(buf, buf, out_end=1, in_start=1)
105-
106-
if (buf[1] & 0b00011000) != 0b00011000:
100+
# Try and verify this is the RTC we expect by checking change in secs
101+
check = self.datetime_register.tm_sec
102+
time.sleep(1.1)
103+
if self.datetime_register.tm_sec == check:
107104
raise ValueError("Unable to find DS3231 at i2c address 0x68.")
108105

109106
@property

0 commit comments

Comments
 (0)