Teensy4.1 - i2c not seeming to work

Dimitri

Well-known member
Hi All,

First time playing with i2c on a Teensy4.1, but I have done is a bunch with other controllers. I load the code below, but I see nothing on my oscilloscope on pins 16, 17, 18, & 19. All 4 pins just sit at 3.3V. No clock, no data, nothing.

Any ideas?

Thanks!

Code:
#include <Wire.h>
#include <WireIMXRT.h>
#include <WireKinetis.h>

const byte pinOut_LED = 13;

uint8_t Temp_A = 0;

unsigned long t1,t2,t3,t4,t5;
unsigned long cycleTime_ms = 200;


///////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
  pinMode(pinOut_LED,OUTPUT);
  digitalWrite(pinOut_LED,HIGH);
  Serial.begin(115200);
 
  delay(100);
  Wire.begin();
  Wire1.begin();

  t1 = millis();
  t2 = t1;

}

///////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  t1 = millis();
  
  if(((t1-t2) >= cycleTime_ms) || (t2 > t1)) 
  {
    
    Serial.print(Temp_A);
    Serial.print(" ");
    Serial.println();

    Wire.beginTransmission(0x01);
    Wire.write(Temp_A);
    Wire.endTransmission();

    Wire1.beginTransmission(0x03);
    Wire1.write(Temp_A);
    Wire1.endTransmission();
    Temp_A++;
    
    t2 = t1;
  }
}



///////////////////////////////////////////////////////////////////////////////////////////////
 
I'm running your program on a Teensy 4.1 right now. Nothing connected to the pins other than my oscilloscope, not even real pullup resistors (only the weak internal pullups).

i2cpins.jpg

This is what my oscilloscope sees on those 4 pins.

file.png
 
Hi Paul,

Thanks for the response - When I try a second Teensy that I have here, I get the correct waveform. Trying to determine why the first unit was giving me problems yesterday.....


Thanks again!
 
Hi Paul, one more thing...

Is it necessary to have this code in the project:

Code:
#include <WireIMXRT.h>
#include <WireKinetis.h>

Thanks
 
You only need to include Wire.h. Those others are used internally inside the library.

I believe all of them will be included into your sketch if you use the Arduino menu item: sketch->Include library.

We could avoid that if we updated the library.properties file and added the includes line:
includes - (available from Arduino IDE 1.6.10) (optional) a comma separated list of files of the library to be added to the sketch as #include <...> lines. This property is used with the "Include library" command in the Arduino IDE. If the includes property is missing, all the header files (.h) on the root source folder are included.
 
Back
Top