PDA

View Full Version : TwoWire::endTransmission always return 0



sumotoy
11-16-2012, 11:00 PM
I'm tying to write a simple I2C scanner but since seems I cannot use the twi.h lib I've tried to use the ability of wire.endTransmission() function to check if device acknoledge.

small example



byte dummy;
for (char id=1; id<=100; id++) {
Wire.beginTransmission(id);
Wire.write(&dummy, 0);
if (Wire.endTransmission() == 0)
{
Serial.print("[[0x");
Serial.print(id,DEC);//found
Serial.print("]] ");
}
else {
Serial.print("0x");
Serial.print(id,DEC);
Serial.print(" ");
}
}


This will aways return all devices found since wire.endTransmission() on teensy 3 always return 0! Th's a way to get around this?

el_supremo
11-17-2012, 12:59 AM
I've figured out a patch which will make the scanner respond properly (at least it does for me).
Line 150 in teensy\arduino-1.0.2\libraries\Wire\Wire.cpp is a "break;" statement.
Change it to:

return 4;


Pete

sumotoy
11-17-2012, 02:51 AM
thanks pete, I will try later, good catch! :) I think this fix (plus the 3 other possible returns, if applicable) must be included in next release!