I2C ports on Teensy 4.1

Status
Not open for further replies.

teensy_teen

Active member
Hi, am I correct that those three I2C channels/buses (SCL-SDA, SCL1-SDA1, SCL2-SDA2) on the Teensy 4.1 are addressed differently? Can all three of them be used to gather data in real-time and "concurrently" without switching? For example:

Channel1 (SCL-SDA) -->SensorA->Sensor-B
Channel2 (SCL1-SDA1) -->SensorA->Sensor-B
Channel3 (SCL2-SDA2) -->SensorA->Sensor-B

where SensorA in all three channels can have the same I2C address and similarly SensorB in all three channels can have the same I2C address as long as SensorA and SensorB use different I2C addresses?
 
Sorry I don't fully understand your question in particular: real-time and "concurrently" without switching?

Simple answer is probably yes.

That is if you are asking, can I have sensors with the same IDs on all three I2C ports and interact with them, the answer is YES. You can do the
Wire.beginTransmission(SENSORA_ID)...
Wire1.beingTransmission(SENSORA_ID)...
...

Now if your question is, can I interact with all three busses at the same time, the answer is YES, BUT:

The Wire library is setup to only talk to one thing at a time... That is when you do calls like: Wire.beginTransmisstion()... Wire.endTransmission(), the end will not come back until done...

It has been awhile since I looked at the I2C_t3 library, so I don't know if it has been ported to T4.x yet or not, but I believe it has DMA and maybe async support.

Also you could write your own code that makes a version of Wire library that looks at all three busses to see the state and work from there.

But again: you may be able to get some concurrent stuff done on some sensors depending on how they work and what support is in the underlying library (or your code). For example if you have one that does something like a Time Of Flight sensor, where you might do one Wire command to start up a logical Ping, you might be able to start up one all all three busses and then maybe then check to see if each ping has completed...

For example recently I played with the Adafruit VL53... library(https://github.com/adafruit/Adafruit_VL53L0X) and added support to read from multiple ones over multiple IO ports and then check the status of them... I also added an example of doing this to their library(https://github.com/adafruit/Adafrui...l0x_multi_extended/vl53l0x_multi_extended.ino) which does this.



Hope that helps.
 
Thank you. Sorry for the confusion. I am considering whether or not to use an I2C multiplexer. If we use an I2C multiplexer, the multiplexer needs to switch to different channels and time is lost due to switching. Important data might have been missed. By "concurrently", I mean no need of switching and data from all three channels flow into the Teensy 4.1 at the same time. In my example, the Teensy 4.1 gathers data from all six sensors at the same time and thus faster and the chance of missing of important data is lower. Not sure if the Teensy 4.1 can do that natively straight out of the box. Perhaps Paul the developer of Teensy can answer this?
 
@Paul obviously knows more about a lot of the system, but I am not sure he can give you a more complete answer than what I have already mentioned without more details.

For example simple things like: what Sensors? Which libraries?

I personally am making the assumption that your sensors are slave devices to the Teensy. That is they are not multi-master, so they respond to requests from the Teensy?

Again with two of the TOF sensors and their corresponding libraries, they used to be setup for example that when you wanted to do a distance reading, there was one member in the library, that started up the ping operation over I2C and then spun there waiting for the ping to complete, at which point it retrieved the data from the device and returned... So if you have several such devices the time get their values can add up... Which again if your devices work like this... Than you could run into issues.

In my case here again, the device also has an additional IO pin that one can optionally set/clear/toggle... That the device might use to tell you that an event has happened. At which point you can simply check the state of the IO pin or have an IRQ or... which your code can use to control when you might then do a query.

I don't believe these two Adafruit libraries, I mentioned one on the previous post, but also played with the VL6... sensor and example: https://github.com/adafruit/Adafruit_VL6180X/blob/master/examples/vl6180x_triple/vl6180x_triple.ino

That again were written to again do one reading in lockstep and hang until complete...

And I don't think this is uncommon in many sensor libraries... So many times it is probably more an issue with how you hook up a sensor and what support the library gives you to make it possible to work well with other sensors (including multiple of the same one).

Hope that helps.
 
Hi, are those three I2C on the Teensy 4.1 separate independent buses or do they share the same bus?

Are there simpler examples or tutorials on how to get data from I2C device(s) connected to one or multiple I2C buses of the Teensy 4.1?

I may buy some sensors to learn how to do it.
 
They are independent.

Chapter 46 of the Reference Manual (which if you have not already downloaded it, you can get from main PJRC website)... Talks about I2C...

The processor actually has 4 I2C busses built in, but only 3 of them have pins that were fully exposed by the T4.x boards.
The Wire object used LPI2c1 hardware object, Wire1 uses LPI2c3 and Wire2 uses LPI2C4 (so lpi2c2 is not used)...

To use the SCL1/SDA1 marked on the card user Wire1 object... So replace everywhere that uses Wire to instead use Wire1...

Note Many libraries are still hard coded to use Wire object...

Often times, especially in the past, to use a different Wire(I2C) object you would see people make copy of a library (maybe rename it), and edit that copy to change all Wire to Wire1 or Wire2...

Some more recent libraries have been updated or created that allow you to pass in which Wire object to use and these libraries will typically hold onto a pointer (maybe a reference if done by constructor)... to the wire object and take care of everything for you.

The VL... libraries I mentioned are like this and allow you to pass in a pointer to which one. Which is great and they do have examples in these libraries which show it.
 
They are independent.

Chapter 46 of the Reference Manual (which if you have not already downloaded it, you can get from main PJRC website)... Talks about I2C...

The processor actually has 4 I2C busses built in, but only 3 of them have pins that were fully exposed by the T4.x boards.
The Wire object used LPI2c1 hardware object, Wire1 uses LPI2c3 and Wire2 uses LPI2C4 (so lpi2c2 is not used)...

Thank you. Do you mean this one? It was made last year but I think Teensy 4.1 came out this May. The stuffs on I2C is in Chapter 47. Maybe I got the wrong manual? https://www.pjrc.com/teensy/IMXRT1060RM_rev2.pdf

What is the address to access SCL-SDA, SCL1-SDA1 and SCL2-SDA2 if I just modify existing programs written for Arduino to use in Teensy 4.1 as a first simple step for learning?

When you talk about Wire1, Wire2, Wire 3 objects, do you mean those in your program posted on gihub?
 
Thank you. Do you mean this one? It was made last year but I think Teensy 4.1 came out this May. The stuffs on I2C is in Chapter 47. Maybe I got the wrong manual? https://www.pjrc.com/teensy/IMXRT1060RM_rev2.pdf

What is the address to access SCL-SDA, SCL1-SDA1 and SCL2-SDA2 if I just modify existing programs written for Arduino to use in Teensy 4.1 as a first simple step for learning?

When you talk about Wire1, Wire2, Wire 3 objects, do you mean those in your program posted on gihub?

Yes - The T4 and T4.1 use the same reference manual. They have the same processor on it. Main differences are more pins, and easier support for SD, and USB and Ethernet... Plus more memory.

And the Wire library defines the Wire object that talks to the SDA0 and SCL0 (on T4.x cards)... Also on these boards as well as other boards who have a second I2C buss, it defines the Wire1 object, which talks to the SCL1 and SDA1 pins on the T4.x... And the Wire2 object which talks to the SCL2 and SDA2 pins.
 
... Plus more memory.

quick note: the 'more Memory' would be external Flash on PCB is 8MB instead of 2MB and with added bottom side chips - PSRAM or FLASH - the core on chip memory is unchanged. The processor package is different to allow access to the added external pins/features - but as noted the ref manuals and internals are unchanged.
 
Status
Not open for further replies.
Back
Top