Sunday, 23 October 2011

Interfacing 3.3V devices to 5V Arduinos

Frequently 3.3V devices need to interface with 5V ones, for instance when connecting an SD card to a 5V Arduino microcontroller board. There are many tutorials about device interfacing which discuss various simple methods of level translation, such as this Sparkfun one. Usually the focus is on protecting the 3.3V inputs from 5V devices but on the SPI bus consideration should be given to protecting the outputs too because there could be 5V devices sharing the SPI interface with 3.3V devices. Unfortunately the simple methods frequently don't account for this possibility. Here is a way to interface 3.3V and 5V logic safely. This approach also the advantage that it can be used to make shields which will work on both 5V Arduinos (e.g. Uno, Mega2560) and 3.3V ones such as the soon-to-be released Arduino DUE. To demonstrate the concept the circuit diagram for an SD card interface is shown below.

SD card interface for 5V microcontroller (PDF).

The 5V signals are safely converted to 3.3V using a 74VLC244 octal buffer powered from 3.3V. I chose this device because the data sheet states its inputs permit 5V logic levels when powered from 3.3V. It is also available in a DIP package which is very convenient for prototyping. The output enable lines of the '244 are permanently grounded (enabled). For SPI slave devices you can share the 3.3V versions of MOSI and SCK control lines with all 3.3V devices. You'll need separate chip select buffers for each device.

The 3.3V logic level output to the microcontroller (MISO) is buffered through one gate of a 74HCT125 quad buffer. The active-low output enable is tied to the chip select line so that when the SD card is not selected the output of the '125 is put into the high-impedance state. This will also occur should the jumper be removed, which is the reason for the pull-up resistor. The 74HCT125 is powered from 5V, so there is no problem when 5V SPI slave devices are also in use.

I used the above circuit to successfully connect an SD card to a 5V Arduino Mega2560. It is also included in a combined Wi-Fly and SD card shield design that is almost ready for manufacture.

1 comment:

  1. Ooops! There's a bug in the schematic. R1 should be pulled up to 5V. Pulling up to 3.3V can allow current to be sourced to the 3.3V supply. If the current used is less than 17uA (quite possible when the SD card is in sleep mode) then the 3.3V regulator must sink ~17uA. Some regulators can do this, but the TC1262 can't, and the voltage on the 3.3V rail will slowly rise towards 5V. With R1 pulled up to 5V there's no problem.

    The sparkfun tutorial shows an inline resistor circuit with pull-up which features this same problem. In that circuit however the pull-up to 3.3V is intended; there is no fix.

    ReplyDelete