Sensor Interfacing using ATmega8 microcontroller
If you’ve ever tried to hook up a 3.3V sensor to a 5V micro, you know what I’m talking about – connecting these two can be a problem! There are several ways in which a 3.3V device can be safely connected to a 5v microcontroller. This tutorial will detail a few ways in which this can be accomplished.
Below is an example of how NOT to connect a 3.3V device (like the SCP1000-D01 pressure sensor with SPI interface) to a 5V microcontroller (like a PIC or AVR running at 5V). Although you may experience normal operating conditions, the lifespan of your 3.3V device will be dramatically shortened.
Directly connecting the devices together (see above) will overstress the 3.3V device and eventually lead to device failure.
In general, there are many ways to interface these two SPI components together. There are many ICs available on the market that are specifically designed to translate between logic levels. We’ve never used any of them! Historically they’ve been very difficult to source and there are a few methods below that make interfacing logic levels fairly simple.
Inline Resistor –
This is the easiest and most rudimentary way to connect your devices together. Below is a generalized diagram using the inline resistor method.
R7 and R8 : 10K resistors are placed between the MOSI (Master Output Slave Input) line as well as the SCK (clock) line. These resistors will decrease the amount of current flowing into the 3.3V device. The internal clamping diodes within the 3.3V device will attempt to clamp the incoming signal to 3.3V thus protecting the rest of the 3.3V device. Clamping diodes are normally found on the input lines of low voltage devices.
A clamping diode is a diode used to limit the peak voltage on a line to a pre-determined maximum voltage. The resistor reduces the amount of current flowing through the diode by several orders of magnitude. Limiting the current will reduce the chances of the clamping diode being permanently damage. Without the resistors in place, much higher current will flow through the diode. These levels could destroy the clamping diode and in turn, damage the device.
Caution is needed with this approach as it is not guaranteed that your 3.3V device will contain clamping diodes. Although most devices have clamping diodes, if your device does not, then this inline resistor method will not work to reduce the voltage input.
MISO : You should notice that there is no resistor on the output of the 3.3V device (MISO). You shouldn’t need any circuitry between these lines to connect with your 5V device.
For more detail: Sensor Interfacing using ATmega8 microcontroller
Leave a Comment
You must be logged in to post a comment.