Teensy 3.6 - I2C (TWI) clock speed not quite 400 Khz on 256 MHz overclock

Status
Not open for further replies.

dzalf

Member
Dear guys

I am reaching out to you with a question regarding the I2C clock speed of my Teensy 3.6.

I have successfully implemented a communication protocol between a T3.6 and an Arduino Uno. As it can be seen in the image below, the clock speed is 347.2 KHz instead of the configured 400 KHz (of course using Wire.setClock(400000);). As you can see, I can read and write data to the bus and everything works fine after adding some delays before the Wire.beginTransmission() command (mainly after trial and error with different values)

SDS00008.png

I am assuming that the overclock may have affected this timing, however I must emphasize that the communication is working fine. I have also tested the same code at 120 MHz, 180 MHz and 240 MHz however the result is the same. Please keep in mind that my project actually needs that overclock as I am querying a bunch of values from a group of Arduinos in "real time" through the I2C bus while the T3.6 drives an SPI OLED screen, keeps a serial communication and handles extra peripherals.

Is there any workaround to push this frequency a bit higher? More importantly, should I expect any improvements on the communication speed if I get those extra 50 KHz?

As far as I remember there is a .h file that implements the clock dividers for the I2C communication when overclocking but I am not certain if it is possible to fine-tune the clock values.

Thank you very much for your help and stay safe!

dzalf :cool:
 
The first thing that jumps out at me is that if you change the clock source frequency, you also have to set the clock and divider registers in order to track with that. It's the same problem as figuring out how to set up the DMA registers.

You already got an oscilloscope, so you can tell pretty easily if what you try worked!
 
The first thing that jumps out at me is that if you change the clock source frequency, you also have to set the clock and divider registers in order to track with that. It's the same problem as figuring out how to set up the DMA registers.

You already got an oscilloscope, so you can tell pretty easily if what you try worked!

Dear Pilot

Thanks for your reply.

Based on what you said, it means that effectively I must fiddle with the dividers on the adequate file (I assume it's a .h).

I always thought that the selection of the adequate dividers would be done "automatically" when selecting the system clock value via a preprocessor directive or similar. Otherwise, could you point me at the name of the file that I have to edit?

Thank you once again

dzalf
 
Otherwise, could you point me at the name of the file that I have to edit?

The links and files and other details mentioned in this answer are for Teensy 3.6.

Edit WireKinetis.cpp if you want to control the clock speed settings.

For documentation about the "F" register, look in the MK66FX1M0 manual on page 1876.

For the relationship between CPU clock speed and F_BUS speed (or to change them), refer to kinetis.h.

You might also try a lower value pullup resistor before you dive into the code. These chips automatically wait for slow rise times by watching the voltage on the pin after they turn off their N-channel transistor which pulls the line low.
 
Dear Paul

Thank you very much for your kind help.

I will definitely have a look to the datasheet and the .cpp file and try to get a good understanding of the clock speed adjustment.

With regards to the resistors, in fact I forgot to mention a VERY important fact. I am using the level shifting technique described in this application note since my protocol is between Arduino and Teensy. I am well aware that this topology is generally NOT recommended for fast speed I2C protocols, however as far as I understand that applies for communications running past 1 Mbps or so. I have about 80% confidence that my problem lies on this fact, however, why would the creators of the I2C protocol would recommend it if it wasn't adequate for the speeds I intend to achieve? On the other hand, I must say that my I2C clock is VERY close. I would be thrilled to see that 50 kHz increase. :D

As soon as I have improved something or if I have any more questions I will come back again tomorrow (because it's 3:00 am here in the UK :( ).

Let's leave the thread open for now.

Stay safe

Cheers

dzalf
 
Status
Not open for further replies.
Back
Top