Teensy 3.6 - multiple I2C ports still 1 bus and therefore all same speed?

Status
Not open for further replies.
Hello,

I have a selection of sensors I would like to connect with I2C. Most will support 400Khz I2C but 2 are SMBus 100Khz. Reading the datasheet for the K66 it seems the multiple I2C interfaces are really the same bus and is basically multiplexed. Is this correct? Therefore do all ports will need to work at the same speed? I know I need to have the pull-up on each port but not sure about the speed aspects.

I was wondering if I could put my 400Khz sensors on Wire (for example) ad 100Khz on Wire1 and have the different ports running at the top speed of the various sensors. (I believe some of them actually run over 400Khz speed)

Thanks, Jeff
 
These code snippets set up two I2C buses on a T3.5, both at 400kHz:

Code:
#include <i2c_t3.h>                            // I2C for teensy (replaces wire.h)
.
.
void setup {
.
.
Wire.begin (I2C_MASTER,0x00,I2C_PINS_18_19,I2C_PULLUP_EXT,400000); // SDA0/SCL0 I2C at 400kHz
Wire1.begin(I2C_MASTER,0x00,I2C_PINS_37_38,I2C_PULLUP_EXT,400000); // SDA1/SCL1 I2C at 400kHz
.
.

}

Those 400000 values set the bus speeds. Now I haven't tried using different bus speeds myself but I'm pretty confident it will work, (although i'd be happy to be proven wrong!).

Have a look at the documentation for the the i2c_t3 library on GitHub where it explains how to set different bus speeds.

let us know how you go!
 
Last edited:
Hello,

Yes, I saw the i2c_t3 library and that is what spawned this thread as it didn't seem to confirm the ports are truly independent, I think I actually saw something in the i2c_t3 thread that they were basically a mux'd bus and not sure if each treated the same as I have a i2c mux chip somewhere here that all ports still run at the same speed.

Anyhow, I ran the advanced scanner example for i2c_t3 and it did find my 100Khz sensors only when that port was set to 100Khz so that looked promising. I then spent the last couple of nights moving several sensor libraries over to i2c_t3 compatibility so I could test the sensors properly.

I can confirm that each port can have it's own speed with i2c_t3 library. I have Wire and Wire1 at 400Khz and Wire2 at 100Khz and all my sensors seem to be responding using that timing. If I change the 400 to 100 I get a change in clock and slower replies. Have not setup to the logic analyzer to confirm the timing but I feel pretty safe that its correct for each port.

Thanks, Jeff
 
Thanks. I did download the datasheet and did some reading there first but wasn't looking for the right thing and still learning on how to find what I need in large complex datasheets. Still kinda new to these microcontrollers. I would have seen it if was looking for 'frequency divider' and if it had 'clicked'.

Thanks, Jeff

For questions like this, it is sometimes best to go to the datasheets, which you can download from: https://www.pjrc.com/teensy/datasheets.html


If you go to the K66 manual (https://www.pjrc.com/teensy/K66P144M180SF5RMV2.pdf) chapter 58 you will see that there are separate registers for each of the SPI busses, including things that generate the different speeds ...
 
Your welcome,

Note: Actually in these cases I look at two things. The manual and the existing code base... For example if you look in Wire.cpp you find a method setClock where you pass in the frequency to use. It is in here where you see they set the F register (I2C0_F), which depends on the BUS speed as well as the frequency you passed in.

If you look in kinetis.h you see that I2C0_F is defined as: #define I2C0_F (KINETIS_I2C0.F)
A few lines above you will see where KINETIS_I2C0 is defined which is a specific address and part of a structure which is defined just above that... That structure matches the registers as defined in the section of the manual.

I believe this is done in i2c_t3 library in the method: i2c_t3::setRate_
It might be slightly harder to follow it in here as for example he is using a pointer to which i2c register set to use *(i2c->f) =
And he is generating the settings versus coded by if statements... But same result.
 
Status
Not open for further replies.
Back
Top