ESP32 I²C 5V tolerance
ESP32 I²C 5V tolerance
Hello,
as part of my current ESP32 project, at some point I would like to link up my ESP32 WROOM with an Atmega328P-PU on a PCB, using I²C.
I've got a working perfboard prototype of the Atmega circuit, and on it, I've pulled the I²C SDA and SCL pins up to 5V with two 4K7 resistors. This seemed like a good idea because the Atmega and ESP32 will be installed inside a car with about 15 ft of wire between them on the I²C bus, and the Atmega itself runs on 5V in the first place.
Now, I think I read somewhere that the ESP32 I²C pins are 5-volt tolerant, provided that you use higher-value resistors, maybe like my 4K7 ones.
Is this true, or do I need a level shifter of some kind to connect the Atmega perfboard circuit and the ESP32?
as part of my current ESP32 project, at some point I would like to link up my ESP32 WROOM with an Atmega328P-PU on a PCB, using I²C.
I've got a working perfboard prototype of the Atmega circuit, and on it, I've pulled the I²C SDA and SCL pins up to 5V with two 4K7 resistors. This seemed like a good idea because the Atmega and ESP32 will be installed inside a car with about 15 ft of wire between them on the I²C bus, and the Atmega itself runs on 5V in the first place.
Now, I think I read somewhere that the ESP32 I²C pins are 5-volt tolerant, provided that you use higher-value resistors, maybe like my 4K7 ones.
Is this true, or do I need a level shifter of some kind to connect the Atmega perfboard circuit and the ESP32?
Re: ESP32 I²C 5V tolerance
A level shifter at esp32 side would be a good idea, also some transient protection. And you may want to consider using pjon.
Re: ESP32 I²C 5V tolerance
Would a level shifter simply be "a good idea", or will it actually be needed? Can the I²C pins on the ESP32 tolerate 5V or not?
Transient protection is taken care of, I will be using a TVS diode combined with a fuse and a choke, in front of a 3V3 DC converter down from the car's 12V to power the ESP32. And the Atmega PCB will have a similar setup, except with a 5V voltage converter.
On the other hand, the Atmega can be run at 3V3. Could I just change the Atmega's power supply from 5V to 3V3 and then run the I²C bus across those 15 ft of wire on 3V3? Or would that just not be enough to ensure a reliable I²C data transfer?
Transient protection is taken care of, I will be using a TVS diode combined with a fuse and a choke, in front of a 3V3 DC converter down from the car's 12V to power the ESP32. And the Atmega PCB will have a similar setup, except with a 5V voltage converter.
On the other hand, the Atmega can be run at 3V3. Could I just change the Atmega's power supply from 5V to 3V3 and then run the I²C bus across those 15 ft of wire on 3V3? Or would that just not be enough to ensure a reliable I²C data transfer?
-
- Posts: 9724
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32 I²C 5V tolerance
Not sure if you can just install current limiting resistors in this situation... I2C is both open-drain and bidirectional, so at least in one direction, the current limiting resistors will form a resistive divider with the pull-up resistors I2C requires. I'd go for a real level shifter with this if you want to use this at 5V. Another option, however, may be to run the I2C lines at 3.3V (as in: connect the required pull-ups to 3.3V instead of 5V): if I recall correctly, the ATMega at 5V will happily recognize these signals as valid and you won't need any shifters. Because I2C is open-drain, even when the ATMega is run at 5V, it will only pull the I2C lines down and never up to 5V.
Re: ESP32 I²C 5V tolerance
I've just ordered a two-channel bi-directional level shifter off eBay for this specific purpose.
Considering I've got 15 ft of wire to overcome in a noisy car environment, it's probably really best to run the I²C bus at 5V and then only shift it down to 3V3 at the ESP32 input pins.
Considering I've got 15 ft of wire to overcome in a noisy car environment, it's probably really best to run the I²C bus at 5V and then only shift it down to 3V3 at the ESP32 input pins.
Re: ESP32 I²C 5V tolerance
I meant transient protection on the gpio lines. I still say you should consider differential signaling or pjon instead of i2c.
Re: ESP32 I²C 5V tolerance
According to ATmega328p Datasheet, you can even run you Atmel MCU as low as @1.8V.
If you do Arduino. As far as I can remember, there is also some Arduino Micro Pro running @ 3.3V. Perhaps you wanna check them out.
Cheers
Gfast2
If you do Arduino. As far as I can remember, there is also some Arduino Micro Pro running @ 3.3V. Perhaps you wanna check them out.
Cheers
Gfast2
Re: ESP32 I²C 5V tolerance
I think I will still keep the Atmega running at 5V. I'm too far into the project already with the Atmega to change it to 3V3, as a bunch of sensor readings depend on the 5V for reference. I would have to make fundamental changes to my code and my perfboard layout.
Just keeping it on 5V as it is seems the better idea, and then just put a $1 level shifter between the Atmega and the ESP32. And my guess is that along 15 ft of wire inside a car between the Atmega and the ESP32, 5V guarantees a more stable I²C than 3V3. I've had people telling me that I²C over such a distance is a very bad idea in the first place, but all I can say is that at home in my workshop, it worked perfectly if I pulled the wires up to 5V with 4K7 resistors, as is the general advice when using the I²C bus on the Arduino.
Just keeping it on 5V as it is seems the better idea, and then just put a $1 level shifter between the Atmega and the ESP32. And my guess is that along 15 ft of wire inside a car between the Atmega and the ESP32, 5V guarantees a more stable I²C than 3V3. I've had people telling me that I²C over such a distance is a very bad idea in the first place, but all I can say is that at home in my workshop, it worked perfectly if I pulled the wires up to 5V with 4K7 resistors, as is the general advice when using the I²C bus on the Arduino.
Re: ESP32 I²C 5V tolerance
Many years before, I did a project using rs-485 chips (sn75176). It's dirty cheap and helps me programming my Arduino (Mega 2560) from a distence about 15m-20m away. If the I²C in your project not rocks, try this one.
Cheers
Gfast2
Cheers
Gfast2
Re: ESP32 I²C 5V tolerance
Hi megabite,
To add a little bit to the existing range of comments here:
To add a little bit to the existing range of comments here:
- To meet the ESP32 "maximum voltage" specification, you can't pull ESP32 pins up to 5V. So if this is, for example, going in a product you will sell or rely on for some very important function, don't do that.
- However, pulling up to 5V via 4.7K resistors will only bleed approx (5-3.3)/4700 amps of current into the ESP32's snapback overvoltage protection circuit. So approx 0.3mA. This is probably not enough to cause any damage or malfunction. So if this is a personal project, you can probably take the risk.
- If you don't want to take the risk, you can use any two cheap N-channel FETs to level shift I2C (NXP has an app note for this: http://www.nxp.com/documents/applicatio ... N10441.pdf )
- I worked on a product a few years ago where we added an I2C differential transceiver - PCA9614DP - to deal with this kind of electrically noisy environment. Or as GFast2 says you could try an inherently differential protocol like RS-485.
- If you want to keep it simple with single-ended signals (ie I2C), consider adding a low value series resistor and a protection diode at both ends of both I2C lines. Something like R3,R4,D1 & D2 in the first image here: https://electronics.stackexchange.com/q ... on-circuit (choose R3/R4 values in the 50-100 ohm range and for D1/D2 a TVS or failing that a zener diode with a breakdown voltage above 5.5V.) You'll still only need the pullups (R1/R2 in that picture) at one end, unless you're level shifting.
- Consider how you're doing grounding, as the two ends will need to see the same ground for single-ended signalling to work. Traditional automotive grounding via the chassis will also be noisy (there's a reason all automative data buses are differential!)
- May work fine without these in your car, who knows?!? Let us know what you end up doing and how it works out.
Who is online
Users browsing this forum: No registered users and 190 guests