Bidirectional 3.3v 5v Level Shifter

Hi guys.. welcome to another simple DIY project...
Lets make a level shifter, which will just shift a 5v data line to 3.3v or vice versa...
Okie why we need such a shifter..  ? or what is this stuff actually.... ?
We run around huge bunch of devices that run in various voltage levels..
for example Raspberry Pi runs in 3.3v, and its all GPIO I/O pins are at this level, even though we provide a 5v USB input. And so it is not tolerent to 5V input levels from another device or sensor modules connected to it over I/O pins using SPI, UART, i2C... whatever....
Another example is Arduino UNO which runs in 5V, normally is driving all its I/O at 5V levels.
 So interfacing boards at different I/O voltage levels requires a level shifter. Simple voltage divider circuits can help for an extent.. but they dont provide low voltage  device protection or bidirectional shifting.
Wait a minute ... Bidirectional... what is it ?
Okie.. some communication protocols like i2C are bidirectional, ie same physical line(s) are used to send data back or forward. They will have some intelligent methods to identify this flow. So to connect two different voltage level devices using such bus types, we will be needing a bidirectional level shifter.

So its always handy if you have a 2 or 4 channel level shifter in your shack.
Lots of ready-made level shifters are available in internet But always DIY has its beauty.. rite ? guys ??

And the circuit idea is nothing new, which is based on level shifter application note by Philips long back.  (see figure 2 in page 10)

Difference is that we use a cheaply available MOSFET 2N7000 in indian market

Lets see the circuit first...














   So the above circuit shows a single channel bidirectional level shifter. You will need minimal of two channels for simple UART or I2C.

A little explanation always helps ...
  2N7000 is a N-channel Enhancement type MOSFET which needs a minimal positive Vgs to turn on the D-S conduction. As you can see here, the MOSFET is biased from the 3.3v device, so it makes sure that low voltage device is safe even when it is switched off and no 5v signals reach the device input lines.

It is shown that the level shifter circuit pulls up both data lines to their respective device's supply voltages (3.3v or 5v ). This seems only good for lines which are not already pulled up. But actually the pull-up in level shifter does no harm to whether the data lines are already pulled up or not. Arduino's micro-controller have weak internal pull-up resistors for its I/O lines.

So lets see how it does the function... Assume both devices are ON...So inherently the MOSFET is in non-conducting state because all its pins are pulled up to either 3.3v or 5V.

A logical HIGH from 3.3v device side makes the 2N7000 to remain turned off since both gate and source are at 3.3v level now. So the output line keeps tied to 5v level , making a logical HIGH at 5v device side.
A logical LOW from 3.3v device side makes the 2N7000 to turn ON because it creates a sufficient Vgs between gate and source. So the output line ties to input line through MOSFET which makes both somewhere less than 0.1V, making a logical LOW at 5v device side also.

Now..
A logical LOW from 5v device makes the internal diode (drain-substrate diode) to make Vgs reach its threshold and hence allow MOSFET conduct. This further makes the 3.3v device side to a logical LOW.

A logical HIGH from 5v device has nothing to do with anything because all the pins are high and hence the MOSFET remains in non-conducting state, which results to logical HIGH at 3.3v device.


Above is my prototype.. done on a parallel lines track PCB. .Tested for both UART and I2C between Raspberry pi and Arduino UNO R3.

LAST NOTE: It is always good to short GND of two devices that you are using . Even though not shown here in circuit, take a piece of wire and short the ground pins on both boards.

Comments

Sean said…
Hi, I'm looking to build a level shifter for a radio project using a RDA5807m(3.3v max), standalone atmega (5v), and a 16x2 LCD(5v). Going to be needing a level shifter. Would the 2N7000 be ok for such a project? If not, could you recommend any other through hole MOSFET?

Popular posts from this blog

DIY Fixing a Laptop Battery

Introducing an FPGA-ARM Dev Kit for Embedded Linux Starters- Avent MiniZED Board