Skip to content

Commit 83e9438

Browse files
authored
Merge pull request #24 from coplate/main
adafruit_ds1307 module does not respect user-changed values for Square Wave output
2 parents a8ca073 + 8dd7fea commit 83e9438

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

adafruit_ds1307.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,21 @@ class DS1307:
9797
def __init__(self, i2c_bus):
9898
self.i2c_device = I2CDevice(i2c_bus, 0x68)
9999

100-
# Try and verify this is the RTC we expect by checking the rate select
101-
# control bits which are 1 on reset and shouldn't ever be changed.
100+
# Try and verify this is the RTC we expect by checking constant fields.
101+
# These fields are described as "0 = Always reads back as 0." in spec.
102102
buf = bytearray(2)
103103
buf[0] = 0x07
104104
with self.i2c_device as i2c:
105105
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
106106

107-
if (buf[1] & 0b00000011) != 0b00000011:
107+
if (buf[1] & 0b01101100) != 0b00000000:
108+
raise ValueError("Unable to find DS1307 at i2c address 0x68.")
109+
110+
buf[0] = 0x03
111+
with self.i2c_device as i2c:
112+
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
113+
114+
if (buf[1] & 0b11111000) != 0b00000000:
108115
raise ValueError("Unable to find DS1307 at i2c address 0x68.")
109116

110117
@property

0 commit comments

Comments
 (0)