File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments