Teensy 4.0 can´t see a I2C device in port 1

Status
Not open for further replies.

Vahen1981

Member
Hi everyone!
I'm trying to solve this, but I can´t find any information who helps me untill now, so I decide to ask the community. This is the problem:

I'm trying to use an lcd 1602 through I2C port 1, when I did in port 0 everything goes perfect, but I can´t do it in port 1. I used the "scanner" example of the Wire library, and it shows "No I2C devices found". I also tried with other I2C libraries, but nothing happened... Any idea? TRhanks!
The example code:



Code:
#include <Wire.h>


void setup() {
  // uncomment these to use alternate pins
  Wire.setSCL(16);
  Wire.setSDA(17);
  Wire.begin();
  Serial.begin(9600);
  while (!Serial);        // Leonardo: wait for serial monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println(F("Scanning..."));

  nDevices = 0;
  for (address = 1; address < 127; address++) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print(F("Device found at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.print("  (");
      printKnownChips(address);
      Serial.println(")");

      nDevices++;
    } else if (error==4) {
      Serial.print(F("Unknown error at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println(F("No I2C devices found\n"));
  } else {
    Serial.println(F("done\n"));
  }
  delay(5000);           // wait 5 seconds for next scan
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x30: Serial.print(F("Si7210")); break;
    case 0x31: Serial.print(F("Si7210")); break;
    case 0x32: Serial.print(F("Si7210")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615,Si7210")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021,MS8607")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591")); break;
    case 0x4A: Serial.print(F("ADS1115,Qwiic Keypad")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080,Qwiic Keypad")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x6F: Serial.print(F("Qwiic Button")); break;
    case 0x70: Serial.print(F("HT16K33")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}
 
If the scanner did not find it then perhaps it is wired up incorrectly or to the wrong pins
 
Thanks for your answer, actually I checked the connection many times and that is ok... I think is a problem of the port 1, because there is no problem if I use the port 0
 
Sorry the default scanner only scans Wire not Wire1 or Wire2.

Below is a scanner which will scan 3 Wire channels.
Its not mine but modified by someone on this forum. I can't remember who.

Code:
// i2c_scanner
// http://playground.arduino.cc/Main/I2cScanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

// BUGBUG::Should put this in WireIMXRT.h
#if defined(__IMXRT1062__)
#define WIRE_IMPLEMENT_WIRE
#define WIRE_IMPLEMENT_WIRE1
#define WIRE_IMPLEMENT_WIRE2
#endif
typedef struct {
  TwoWire *_wire;
  const char * wire_name;
  IMXRT_LPI2C_t * const port;
} wire_list_t;

wire_list_t wireList[] = {
  {&Wire, "Wire", &IMXRT_LPI2C1}
#if defined(WIRE_IMPLEMENT_WIRE1)
  , {&Wire1, "Wire1", &IMXRT_LPI2C3}
#endif  
#if defined(WIRE_IMPLEMENT_WIRE2)
  , {&Wire2, "Wire2", &IMXRT_LPI2C4}
#endif
#if defined(WIRE_IMPLEMENT_WIRE3)
  , {&Wire3, "Wire3"}
#endif
};
const uint8_t wirelist_count = sizeof(wireList) / sizeof(wireList[0]);


void setup() {
  // uncomment these to use alternate pins
  //Wire.setSCL(16);
  //Wire.setSDA(17);
  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    wireList[wirelist_index]._wire->begin();
  }
  Serial.begin(9600);
  while (!Serial);        // Leonardo: wait for serial monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  byte error, address;
  int nDevices;

  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    IMXRT_LPI2C_t * const port = wireList[wirelist_index].port;
    Serial.print(F("Scanning("));
    Serial.print(wireList[wirelist_index].wire_name);
    Serial.println(F(")..."));
    nDevices = 0;
    for (address = 1; address < 127; address++) {
      // The i2c_scanner uses the return value of
      // the Write.endTransmisstion to see if
      // a device did acknowledge to the address.
      wireList[wirelist_index]._wire->beginTransmission(address);
      error = wireList[wirelist_index]._wire->endTransmission();

      if (error == 0) {
        Serial.print(F("Device found at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.print("  (");
        printKnownChips(address);
        Serial.println(")");

        nDevices++;
      } else if (error == 4) {
        Serial.print(F("Unknown error at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.printf("MCR:%x MSR:%x, MIER:%x MDER:%x MCFGR0:%x MDMR:%x MCCR0:%x\n",
          port->MCR, port->MSR, port->MIER, port->MDER, port->MCFGR0, port->MDMR, port->MCCR0);
      }
    }
    if (nDevices == 0) {
      Serial.println(F("No I2C devices found\n"));
    } else {
      Serial.println(F("done\n"));
    }
  }
  delay(5000);           // wait 5 seconds for next scan
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591")); break;
    case 0x4A: Serial.print(F("ADS1115")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x70: Serial.print(F("HT16K33")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}
 
Thank you again! I tried that code, but is still showing "No I2C devices found" :(
Maybe I should use the i2c_t3 library? But the documentation tells that is not compatible with teensy 4.0
 
I wired a DS3231 to I2C port 1 on a Teensy4.1 and ran the code from @BriComp's msg#4.
It finds the device:
Code:
I2C Scanner
Scanning(Wire)...
No I2C devices found

Scanning(Wire1)...
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

Scanning(Wire2)...
No I2C devices found

Does your LCD have pullups on SDA and SCL? If not, they are required - I use 3.3K on each of SDA and SCL.

Pete
 
Thanks for running the code, I think everything is fine with the LCD because if I connect in port 0 (pin 19, 18) the scanner detectets inmediately, but in port 1 (pin 16, 17) nothing happened.
 
Post a photo of how you've connected the LCD to pins 16 and 17.
Does the LCD use 5V or 3V3?
Does your LCD have pullups on SDA and SCL?

Pete
 
Hello Pete!
Here are some photos

First the connections in teensy, red wire in pin 16 (SCL1) and blue wire in pin 17 (SDA1)
01.jpg

Then, connections in level shifter. Red in LV1, Blue in LV2, 3.3v(orange) and GND(Blue) from Teensy. Then in the other side Green to HV1, Yellow to HV2, and 5v and GND from another source, source that also power the LCD screen
02.jpg

Finally the LCD, green to SCL, yellow to SDA, Orange to VCC and Red to ground.
03.jpg

"Does your LCD have pullups on SDA and SCL?" I'm not sure about this, but I think yes... otherwise I think it would not work on I2C port 0, and in that port everything is ok.
 
your code in post #1 won't work on Teensy 4. There are no alternate pins (as in Teensy 3). To use pins 16 and 17 you must use Wire1, e.g. Wire1.begin() and every place you use Wire replace it with Wire1.

i'm not sure why the scanner in post #4 is not seeing your I2C device ....
 
I can confirm that the I2C to parallel adapter boards on the back of these LCDs do include pull-ups on the SDA and SCL lines.
 
Thanks for the photos.
In photo #2 there's a pair of yellow (HV) and blue (GND) wires. Where do they go? Are they the same yellow and blue wires that go to Teensy pins 18 and 19?

Pete
 
That cables (yellow and Blue) are the reference power for the level shifter (5v and ground)... Do you think could be the library? Maybe someone knows another library that I can use for I2C in teensy 4.0?
 
Again sort of hard to follow your wiring through the pictures. Sorry it is early in morning for me. Eyes are not seeing straight yet.

But I would double check the wiring. That is I know I have screwed up before, where you think you can simply move the pins down 2 (19,18) to (17, 16) for Wire1
But the SCL/SDA are reversed so you need to move 19->16 and 18->17 So I would double check that.
And I know that Wire1 works with the wire library on T4, unless something has corrupted it recently.

As for if you are using a library to communicate to the display, other than your own code, you need to make sure that library is setup to handle alternate Wire objects. Some are, many are not.
 
I don't see how it can be the library. I demonstrated in #6 that the code in #4 (which uses the Wire library) finds an I2C device on Wire1.

I've added a few other devices on Wire(0) and ran #4 again and it finds all of the devices on the two buses:
Code:
Scanning(Wire)...
Device found at address 0x51  (EEPROM)
Device found at address 0x54  (EEPROM)
Device found at address 0x56  (EEPROM)
Device found at address 0x57  (EEPROM)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

Scanning(Wire1)...
Device found at address 0x57  (EEPROM)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

Scanning(Wire2)...
No I2C devices found

and just for fun I moved the extra devices to Wire2:
Code:
Scanning(Wire)...
No I2C devices found

Scanning(Wire1)...
Device found at address 0x57  (EEPROM)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

Scanning(Wire2)...
Device found at address 0x51  (EEPROM)
Device found at address 0x54  (EEPROM)
Device found at address 0x56  (EEPROM)
Device found at address 0x57  (EEPROM)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

I think you have a wiring problem somewhere.
In the first photo, you have yellow and blue wires on Teensy pins 18 and 19. Where do they go?

Pete
 
I had the parts to duplicate your basic setup with the LCD on Port1. It worked as expected, so I suspect there must be a wiring issue somewhere as others have mentioned.

LCD1620 I2C on T4.0 Port1 Wiring.jpg
LCD1620 I2C on T4.0 Port1 Software Output.jpg

--- Ken
 
Status
Not open for further replies.
Back
Top