Using multiple I2C busses without i2c_t3? (Teensy 4.0)

Status
Not open for further replies.

sid8580

Well-known member
Hello,
How would I use the additional I2C busses on the Teensy 4.0, without something like the i2c_t3 library I'd been using with the T3.6? I don't know how to avoid being limited to SCA/SDL 0. The T4.0 has several sets of I2C, is it possible to use them at this point?

Worst case, I will have to try running everything off 1 I2C bus and use a multiplexer if I run into overlapping addresses. Was hoping not to though, I've got a couple of sensors that probably each utilize most of the bandwidth of a bus on their own and I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...
 
Typically Wire1 and Wire2 will initialize to using the next i2c bus pins. I expect that should work on Teensy 4 at this time.

so instead of Wire.begin() it would be Wire1.begin() - the same for all other commands.
 
I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...

Oh, i've run into the same trap. That is because a pre-beta system is marketed under a previously well reputated name.
Unfortunately, it is not possible to program the T4 with the original IDE any more without running into problems, because the fuses have been burnt purposely for Teensyduino. I am about tossing the T4 and writing off the project.
 
Hello,
How would I use the additional I2C busses on the Teensy 4.0, without something like the i2c_t3 library I'd been using with the T3.6? I don't know how to avoid being limited to SCA/SDL 0. The T4.0 has several sets of I2C, is it possible to use them at this point?

Worst case, I will have to try running everything off 1 I2C bus and use a multiplexer if I run into overlapping addresses. Was hoping not to though, I've got a couple of sensors that probably each utilize most of the bandwidth of a bus on their own and I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...

Glancing at the code for Wire indeed the T4 code shows support in \hardware\teensy\avr\libraries\Wire\WireIMXRT.h for:
Code:
extern TwoWire Wire;
extern TwoWire Wire1;
extern TwoWire Wire2;

and in :: \hardware\teensy\avr\libraries\Wire\WireIMXRT.cpp
Code:
TwoWire Wire(&IMXRT_LPI2C1, TwoWire::i2c1_hardware);
TwoWire Wire1(&IMXRT_LPI2C3, TwoWire::i2c3_hardware);
TwoWire Wire2(&IMXRT_LPI2C4, TwoWire::i2c4_hardware);

That is the normal convention for accessing alternate i2c ports.
 
Defragster, thank you! This was one of those things I struggled with early on and found a way out of via i2c_t3, as a side effect it became the ONLY method I knew (at least for the extra busses). Maybe I haven't painted myself into a corner after all :cool:
 
Defragster, thank you! This was one of those things I struggled with early on and found a way out of via i2c_t3, as a side effect it became the ONLY method I knew (at least for the extra busses). Maybe I haven't painted myself into a corner after all :cool:

Originally i2c_t3 was the only way to do multiple I2C buses, but Paul did add support in Wire.h some time ago for multiple I2C buses.

It is unfortunate that there is currently no Teensy 4 version of i2c_t3.
 
Wire1 Works on T4

Had to let a test run last night to SSD1306 i2c display - it is working at 3.3 MHz even with T4 at 912 MHz!

Just now I modified that sketch with this SINGLE LINE after the #includes:
Code:
#define Wire Wire1

That has the compiler change ALL Wire.xxx() refs to Wire1.xxx() with no other changes

I moved i2c wires from #19 and #18 over to #16 and #17 and uploaded sketch is running Just fine at the same rates!

The 3.3 MHz update takes a changed file @mjs513 posted on the T4_Beta thread - where current TD_1.48 max speed is 1 MHz.
 
Status
Not open for further replies.
Back
Top