DIfferentiating I2C ports

Status
Not open for further replies.

Involute

Member
I'm evaluating the feasibility of porting an Arduino Pro Trinket (5V) project to Teensy 3.2 (I have the Teensy up and running on a breadboard). The Trinket project uses the I2C port, of which there's only 1 on the Trinket, but there are at least two on the Teensy. How do I differentiate them in my code?

Also, how are the SDA0 and SCL0 signals on pins 16 and 17 different from those on pins 18 and 19?
 
Wire
Wire1
Wire2

16 & 17 are alternate pins if you dont wanna use 18&19 (dark black are default)

you can use setSCK and setSCL to choose them if you prefer 16&17 before you call Wire.begin()
 
yes sorry, it should be Wire.setSDA(x); and Wire.setSCL(x); then Wire.begin();

if you call Wire.begin() before doing above, it uses the default 18&19
 
Those aren't Arduino commands.

Wire.setSCL() and Wire.setSDA() are Teensyduino extensions. Normal Arduino boards have only fixed pins for those signals. Teensy 3.x & LC have a mux built in. Conceptually it's similar to this Adafruit product, but inside the chip. Those functions allow you to control which pins actually use the SDA and SCL signals.

They can also be used after Wire.begin(). But you do need to use real pullup resistors on all the pins you connect for I2C devices.
 
I'm using a TeensyLC. It does not have enough memory to support Wire AND Wire1. It is possible (reasonable/supported) to switch pins "on the fly" so that most of the traffic goes thru 19/18 and select messages go through pins 22/23? I have tried this without success. I'm just wondering if it is "fool's errand".
 
no, but you can dynamically change the Wire pins from 18/19 to 16/17

Wire will still be used, but the pins its attached to will be dynamically switchable via
Wire.setSCL(16) and Wire.setSDA(17)
 
Wouldn't it be more efficient to leave the I2C pins "as is" and to work rather with different slave addresses? Many I2C devices allow to modify their slave address to avoid conflicts on the bus.
 
unless of course he uses chips which have same addresses, in which case a multiplexer will work, although, even a multiplexer will require additional code to operate...
 
Thanks for the quick replies! I have a master module that uses I2C internally between chips. I don't have control over the addresses of some of these chips (e.g. a dot matrix display from Adafruit). That display has some flexiblity as to address (thx Lady Ada!) but ... I'm integrating this module into a larger system that has a protocol of addresses for different types of modules. thus, to avoid address conflicts, I'm trying to implement and "external" I2C bus in addition to the internal one.

Perhaps I should try to move some of the addresses into a range that is "not likely to be used" (that could bite me later).

Also, r.e. pins. I'm looking at the Teensy LC pinout card. SCL0/SDA0 (in purple) are 91 & 18 respectively. SCL1/SDA1 are 22 and 23 respectively. Am I reading this wrong? I see that 17 and 18 also show SCL0/SDL0, but in more of a shadow form. Does that shadow form indicate that these are available alternate pins for Wire. I guess so. SCL1/SDA1 are default pins for Wire1. Looks like I'll just need to change my board, or use a Teensy 3.2 so that I can do two Wire buses (Wire/Wire1).

Did I get this right?
 
the “shadow” is just alternate pins, which i explained in post #13

technically to switch between both pin sets you’d use setSDA/setSCL, this wouldnt require more memory but you’d need to switch back and forth when accessing the chips based on which theyre physically connected to.
 
tonton81 - thanks for the "walk thru". I needed it. Now I've got to examine my choices and decide which route to take. thanks!
 
Status
Not open for further replies.
Back
Top