Wire.setSCL failure with Teensy 3.5

Howdy all,

I am using the standard Wire library and the Example program "I2Cscanner" in the Examples with a Teensy 3.5.

Teensy 3.5 has default Wire pins as SCL0 on pin 19 and SDA0 on pin 18. I want them to be on SCL2 as pin 3 and SDA2 as pin 4. This is approved of by the Teensy docs.

The Example program i2cscanner has these lines in it

Code:
void setup() {
  // uncomment these to use alternate pins
  
  Wire.setSCL(3);
  Wire.setSDA(4);

  Wire.begin();

but when I run the program , there is no activity on SCL2. There is however activity on SCL0, as measured with an oscilloscope.

Yes, all pins mentioned (3, 4, 18, 19) have 4k7 pullups to 3V3.

This seems very odd. The Example program is unchanged from downloaded, except for uncommenting the two lines contaning the setSCL and setSDA.

All I can think of is that the Teensy pin 3 is not SCL2 (or perhaps I should say it has a different referring number).

Any thoughts ?

Regards, Tony Barry
 
As noted those pins are for Wire2
So all the WIRE commands need to use WIRE2 not WIRE

That should select the right internal hardware to connect those pins.
 
Thank you defragster. Your solution works.

For those who experience the same issue I had with the i2cscanner example and Teensy 3.5, the solution is

1. Do not use the commands Wire.setSCL(3) or Wire.setSDA(4) to access I2C transfers on pins 3 and 4.
2. Instead, change the following multiple lines to use Wire2 instead of Wire.

Code:
#include <Wire.h> //NOTE !! Don't change this to Wire2 ... leave as Wire


void setup() {
  // uncomment these to use alternate pins
  
  Wire2.begin();        // **********change this from Wire to Wire2
  //Wire2.setSCL(3); //***********do not use this option - it does not work !
  //Wire2.setSDA(4); //***********do not use this option - it does not work !

  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.
    Wire2.beginTransmission(address);  // **********change this from Wire to Wire2
    error = Wire2.endTransmission();     // **********change this from Wire to Wire2

    if (error == 0) {
...
 
Great! Also easy to use :: #define WIRE WIRE2

Not sure where those pin numbers came from they don't seem to match any 32 bit Teensy card. The T_3.5 and 3.6 can use ALT WIRE on pins 7&8.
 
Great! Also easy to use :: #define WIRE WIRE2

Not sure where those pin numbers came from they don't seem to match any 32 bit Teensy card. The T_3.5 and 3.6 can use ALT WIRE on pins 7&8.

Hi defragster,

Thank you for the reply.

The pin numbers came from the PJRC Teensy 3.5 Pinouts page.

https://www.pjrc.com/teensy/pinout.html

Scrolling down to Teensy 3.5 Pinouts, we find that pins 3 and 4 are listed as follows:-

Pin 3: PWM CAN0TX SCL2
Pin 4: PWM CAN0RX SDA2
For interest, we note that
Pin 18: A4 SDA0
Pin 19: A5 SCL0

Which makes me think that the pinouts on these cards are a little out of date; certainly SDA0 and SCL0 do work with Wire, and as you so helpfully pointed out (thank you !) SDA2 and SCL2 do work with Wire2 ... but, alas, the Wire.setSDA(4) and Wire.setSCL(3) don't do anything except confuse.

Teensy is such a powerful and attractive device ... but it needs this forum like a mammal needs oxygen. Without the forum, Teensy will surely die.

Regards, Tony Barry
 
You seem to have missed the significance of the final digit. The 2 in SDA2 means that it refers to Wire2 only. The 0 in SDA0 means it refers to Wire
 
You seem to have missed the significance of the final digit. The 2 in SDA2 means that it refers to Wire2 only. The 0 in SDA0 means it refers to Wire

Thank you for your comment, thebigg. There are many things that I have missed the significance of. Coming from a microcontroller background for the past forty years, I am sure there are yet more things to be discovered.

However, if you can explain how ...

Wire.setSCL(pinNumber)

is meant to be used, I would be most grateful.

Regards, Tony Barry
 
Thank you for your comment, thebigg. There are many things that I have missed the significance of. Coming from a microcontroller background for the past forty years, I am sure there are yet more things to be discovered.

However, if you can explain how ...

Wire.setSCL(pinNumber)

is meant to be used, I would be most grateful.

Regards, Tony Barry

Looking at the T_3.5 card. The Compact notations there indicate::

For WIRE [ Wire0 ] - bold is default pin and non-bold is alternate for selection using .setXXX() to use the Alternate pins
pin: function
19 : SCL0
18 : SDA0

17 : SDA0
16 : SCL0
8 : SDA0
7 : SCL0
{also for Wire0 : 22/34 and 47/48}

The same applies to WIRE2 (and other bus types) where there are BOLD for default and non-bold for Alternate
Like WIRE2 : pin 3 for SCL2 and alternate pin 26 for SCL2

The default BOLD pins are selected for compatibility where possible, and where Alternate pins can map to the desired bus hardware they are so indicated.
 
Back
Top