Level shifting advice

I've been playing around with a Nokia 5110 LCD display attached to a Mega, and so have had to deal with level shifting the output from the IO pins from 5V to 3.3V.

Not having a level shifting chip (such as the 4050 buffer) on hand, I just used a simple voltage divider on each pin (33K and 18K resistors).

This simple approach worked fine for this device, but obviously, there must be situations when a chip like the 4050 would be preferred for some reason.

Can someone explain when that might be?

I'd like just like to understand the issues a bit more clearly, so I know when one approach is preferable to another using Arduinos. Thanks.

bluesmoke328: This simple approach worked fine for this device, but obviously, there must be situations when a chip like the 4050 would be preferred for some reason. Can someone explain when that might be?

Yep, it's simple. As long as you are using the I2C interface in one direction only, from the 5V master to the 3.3V slave, it will work OK.

As as soon as you want information back from the slave, you need the proper level converter.

They are a little overpriced on eBay - i.e., more than a dollar, considering the basic (and adequate) one is nothing more than a couple of FETs and a few resistors..

Voltage dividers are okay for slow speed. For reliable high speed with nice clean edges & levels and wiring with any capacitance (implies length and/or multiple devices connected), you need active drivers.

Paul__B: Yep, it's simple. As long as you are using the I2C interface in one direction only, from the 5V master to the 3.3V slave, it will work OK.

If you're using the I2C interface then you don't need anything. Just pull the lines up to 3.3V externally and the open-collector outputs on the chips will do the rest (open-collectors don't ever actively drive the line high, they only pull it to GND).

Of course the horrible Arduino libraries don't let you do that, they turn on the internal pullups which sends the bus to 5V. You have to hack them to get it to work properly (look for "twi_init()" in the file "utility/twi.c").

(And don't get me started on SoftI2C ... ick!)

Open drain if CMOS devices.

Nokia 5110 LCD display uses an I2C iinterface?

CrossRoads: Nokia 5110 LCD display uses an I2C iinterface?

Good question....

...and, no. No it doesn't.

CrossRoads: Voltage dividers are okay for slow speed. For reliable high speed with nice clean edges & levels and wiring with any capacitance (implies length and/or multiple devices connected), you need active drivers.

I see. Can you give some specific examples of devices that would fall into these categories? In particular, what frequency range constitutes "high speed", and what sort of devices devices would need those "nice clean edges"?

Thanks or your patience. I'm trying to get a clearer picture of when you would expect a simple voltage not to work because of the issues you mention.

Anything using SPI for interfacing - SCK is a high speed signal, MOSI/MISO can change with the rising clock edge - so SD cards generally need active buffering. There may some older, slower cards that will work. fat16lib has demonstrated that most newer cards work much better with proper drive circuitry.

Got a display, some pixels get hosed, not a big deal. Saving files to SD card - more critical.

fungus:
Of course the horrible Arduino libraries don’t let you do that, they turn on the internal pullups which sends the bus to 5V.

Which is of course, precisely what you want them to for 5V logic.

Paul__B:

fungus: Of course the horrible Arduino libraries don't let you do that, they turn on the internal pullups which sends the bus to 5V.

Which is of course, precisely what you want them to for 5V logic.

It should really be optional, it breaks the I2C specification.

@ Fungus… The IIC Spec that you are using is not really very current… 400 KHz isn’t the IIC upper limit…
Rather the TWI header file is in need of a small change… in order to make the internal pull up optional.
Further the internal 50K weak pull up is not quite right as it doesn’t really do much for the capacitive load or DI/DT.
Basically the pull up Must be different at high speed… I wouldn’t design anything that required more than 2 cm of track length unless the track width could be 2 1 mm. I looked at some of my old artwork and realized my error… 1 mm is much more accurate with the internal pull up, Again because of the DI/DT issue.
If the TWI class as a whole had an option to disable via an ifdef the weak pullup there would be much less difficulty in making the “Standard” work with mixed device Vcc devices… My background is hardware and I do understand why a PCB trace can be an inductance rather than a “wire”.
I use without thinking a maximum value of 4.7K for the IIC bus pull up and If I need to go off board or cannot apply the 2 mm trace width ‘condition’ I personally will reduce the value of the Pull up. Particularly when there are multiple devices on the same bus.
As bus speed increases PCB traces become transmission lines and it is most necessary to ‘adjust’ the bus current to allow for the DI/DT issue, Especially mixed Vcc loading issues. I have been long considering "Fixing my TWI.h file to make the pull up an option… This is really an issue… again with different device Vcc requirements between the controller and the majority of connected TWI devices, the internal weak pull up is frequently inappropriate and should IMO be an option that is controllable with a minor change to the header file using an ifdef condition that allows for applied Vcc for compatibility with 3V3/5V devices.
While I do understand both the engineering handicapped and the knowledgeable engineer, this is a real issue and I feel one that is ignored by the people that are responsible for writing or reviewing the extant Arduino TWI specifications as the Vcc standards? change. When the initial code was written 3V3 Vcc devices were scarce and somewhat beyond those without a good electronics knowledge base… Thus it was again IMO left alone (dumbed down…) to avoid confusion for the electronically handicapped majority of Arduino issues…
I do remember my own issues when I began to design devices that used lower power supply voltages…
In the early 2000’s I began to change from 5V Vcc to 3V3 Vcc devices/bus voltages and I made a few mistakes… Before I got it, that the issue Is the DI/DT condition or bus loading that begins at 10 cm sq PCB’s with multiple IIC devices. Sometimes to keep within my allowable current budget I had to switch the pull ups off when not in use or use different communication methods to keep my total board current within the solar panel/battery capacity budget required for the design spec/design cost. This was really an issue when I went from 12V SLA to 2.2V gates cell type SLA batteries… I remember one design that Had to be 5V from 2 gates cells… I had a boost converter on board to drive a 12V latching soleniod and I used a 5V linear MAX660?
(I really don’t remember the part # but it was similar to the MCP1702 IQ class device). My solution was to “Tick” the boost device and connect my regulator to the output of the boost device. Since the solenoid storage cap was 4700 uF the Tick was required every few 100 mS or so and done by monitoring the solenoid power supply to generate the tick when the HV bus got close to the regulator dropout point. It worked well although considered a PITA by the contract programmer…
I consider 50K pull ups suitable only for frequencies below 50 KHz and prefer to tri-state anything on the TWI bus if I need to use longer traces between devices, Conservative… Certainly but what I designed always worked… After the initial lesson I learned. It doesn’t cost more that a cheap mosfet and two extra pull ups for the few devices that required different Vcc levels…

Doc

2mm looks huge - that's like a 78.75mil wide trace.

Yes it is… But it works well with 10 - 20 CM bus length’s and although sometimes hard to route especially with the early Protel autorouters…I knew that there would be less “Midnight Oil” sessions on the larger and faster boards used as the systems controllers.
The gain being less current required for the bus itself or in other words insurance against midnight modification of PCB’s to “Fix” “Design Errors” in battery operated devices… or in other words a “Shotgun Cure”. it only took one time for me to understand that being conservative to the extreme wasn’t a bad condition.

Doc
At least the board worked the first time… IT WAS Ugly… Though.