Hi, I have 2 I2C scan functions. One is a self-written one using Wire.h:
Serial.println ("I2C Scanning ...");
byte count = 0;
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.print (" 7 bit address in Arduino)");
Serial.print (" (0x");
Serial.print (2*i, HEX);
Serial.println (" 8 bit address on datasheet)");
count++;
delay (1);
}
}
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
This one can find the correct address under good condition.(no weird operations after powering on the slave)
The other scan function is the one in I2C.h, which has the timeout feature. Details here: I2C/I2C.cpp at master · rambo/I2C · GitHub
The problem with this one is: It always report a problem with the bus, could not complete the scan. But the truth is, all I2C functions (include the self-written scan)works well without running I2c.scan, and after you run I2c.scan() once, nothing works, following is the result of running self-scan;I2c.scan;self-scan
10:06:36.533 -> Serial and I2C setup ready
10:06:42.459 -> Command sent: I2C::scan
10:06:42.492 -> I2C scanner. Scanning ...
10:06:42.492 -> Found address: 46 (0x2E 7 bit address in Arduino) (0x5C 8 bit address on datasheet)
10:06:42.594 -> Found address: 47 (0x2F 7 bit address in Arduino) (0x5E 8 bit address on datasheet)
10:06:42.696 -> Found address: 64 (0x40 7 bit address in Arduino) (0x80 8 bit address on datasheet)
10:06:42.765 -> Done.
10:06:42.800 -> Found 3 device(s).
10:06:55.556 -> Command sent: I2C::sc_an
10:06:55.589 -> Scanning for devices...please wait
10:06:55.623 ->
10:06:55.623 -> Found device at address - 0x0
10:06:55.725 -> There is a problem with the bus, could not complete scan
10:07:08.433 -> Command sent: I2C::scan
10:07:08.468 -> I2C scanner. Scanning ... (program stuck here)
Anyone sees the reason? Thanks