Skip to content

Commit ceeef55

Browse files
authored
Merge pull request #1 from coplate/coplate-patch-allow-square-validation
Updated adafruit_ds1307.py to allow Square Wave settings
2 parents a8ca073 + ae59601 commit ceeef55

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

adafruit_ds1307.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,20 @@ 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 the rate select fields described as "0 = Always reads back as 0."
102101
buf = bytearray(2)
103102
buf[0] = 0x07
104103
with self.i2c_device as i2c:
105104
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
106105

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

110116
@property

0 commit comments

Comments
 (0)