Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: TwoWire::endTransmission always return 0

  1. #1
    Senior Member sumotoy's Avatar
    Join Date
    Nov 2012
    Location
    Venezia, Italia
    Posts
    421

    TwoWire::endTransmission always return 0

    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

    Code:
     
     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?

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,569
    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:
    Code:
    return 4;

    Pete

  3. #3
    Senior Member sumotoy's Avatar
    Join Date
    Nov 2012
    Location
    Venezia, Italia
    Posts
    421
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •