Using I2C between Teensy 3.2 and Mega

Status
Not open for further replies.

Dave Leddon

New member
I'm using a pair of Teensy 3.2 boards to acquire data for use by an Arduino Mega via the I2C bus. The Mega seems to have problems reading the data, some of which is always correct while some is always zero, all within the same message packet. Since the Teensy processors output 3.3 volt data and the Mega expects 5 volt data, is it possible that I require level shifters for the I2C bus.
 
I believe most of the AVR chips have TTL level inputs which work with 3.3V signals even when the AVR runs at 5V. So my best guess is you don't need the level shifter and this is probably a software problem. But adding the level shifter wouldn't hurt. If you have one, or want to buy one (they're usually pretty cheap) you might as well give it a try.
 
Besides a level shifter, sometimes you need pull-down resistors. You would need two resistors, one between SDA and 3.3v and the other betwen SCL and 3.3v. I never used a Mega, but when I was using an Uno, I didn't need pull-down resistors because the AVR had internal resistors that could be enabled, but ARM processors don't have a strong enough resistor within a chip. Typically you would 2.2K resistors on an I2C bus that only has 3.3v components, and 4.7K on a bus with 5v components. You only want one set of pull-down resistors on the I2C bus.

Try to keep the wiring as short as possible.

I answered a similar post a few days ago listing 3 level shifters made for I2C:
 
@MichaelMeissner did you mis typoe and mean 'pull-up' resistors?

@David Leddon is there a common ground wire between the Mega and Teensies?
 
Yes, its pullups for I2C: https://en.wikipedia.org/wiki/I%C2%B2C#Physical_layer

However if you are 3.3V driving 5.0V the pullups might be an issue with the protection diodes
in the Teensy driving them - a dual resistor pullup of 10k to 5V and 2k2 to 3.3V would be
equivalent to a pullup to about 3.6V, preventing the Teensy from seeing 5V, and also giving
a little more voltage margin for the high level sensing in the Mega
 
Turns out that Paul was correct. It was a software issue. After removing two superfluous pull-ups (not needed because the Mega provides them) and installing a bidirectional level shifter on the SLA and SCL lines going to the pair of Teensies, I got the same weird results. On a whim I changed the slave address on the Teensy and viola, it now works. I've got a total of seven devices on the I2C bus and one of them was responding to the same address so the data got interleaved on the receiving end. I don't know how that happened as all I2C addresses are defined in the same location to prevent just this sort of thing from happening, but at least I now know what address not to use.

I have a philosophical question, should I install pull-ups on the Teensy side of the level shifters, or because they're bidirectional, will the Teensy "see" the Mega pull-ups?
 
Status
Not open for further replies.
Back
Top