@@ -578,11 +578,11 @@ def _i2c_write_bytes(self, data):
578
578
for byte in data :
579
579
# Write byte.
580
580
self ._command .append (str (bytearray ((0x11 , 0x00 , 0x00 , byte ))))
581
- # Read bit for ACK/NAK.
582
- self ._command .append ('\x22 \x00 ' )
583
581
# Make sure pins are back in idle state with clock low and data high.
584
582
self ._ft232h .output_pins ({0 : GPIO .LOW , 1 : GPIO .HIGH }, write = False )
585
583
self ._command .append (self ._ft232h .mpsse_gpio () * _REPEAT_DELAY )
584
+ # Read bit for ACK/NAK.
585
+ self ._command .append ('\x22 \x00 ' )
586
586
# Increase expected response bytes.
587
587
self ._expected += len (data )
588
588
@@ -603,6 +603,21 @@ def _verify_acks(self, response):
603
603
if byte & 0x01 != 0x00 :
604
604
raise RuntimeError ('Failed to find expected I2C ACK!' )
605
605
606
+ def ping (self ):
607
+ """Attempt to detect if a device at this address is present on the I2C
608
+ bus. Will send out the device's address for writing and verify an ACK
609
+ is received. Returns true if the ACK is received, and false if not.
610
+ """
611
+ self ._idle ()
612
+ self ._transaction_start ()
613
+ self ._i2c_start ()
614
+ self ._i2c_write_bytes ([self ._address_byte (False )])
615
+ self ._i2c_stop ()
616
+ response = self ._transaction_end ()
617
+ if len (response ) != 1 :
618
+ raise RuntimeError ('Expected 1 response byte but received {0} byte(s).' .format (len (response )))
619
+ return ((response [0 ] & 0x01 ) == 0x00 )
620
+
606
621
def writeRaw8 (self , value ):
607
622
"""Write an 8-bit value on the bus (without register)."""
608
623
value = value & 0xFF
0 commit comments