0

I was following this guide from Adafruit to flash an Arduino with a Pi using AVR-Dude over SPI: https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins?view=all

I noticed that they were not using a level shifter to protect the Pi's 3.3V GPIO from the Arduino's 5V. So I was curious about when a level shifter should be used? Such as this: https://www.adafruit.com/product/1787

The problem is that most level shifters provide 4 channels(the 8 channel one is sold out). If I wanted to flash one device there isn't a problem because then all 4 channels are used(MISO, MOSI, SCK, & RESET). If I wanted to flash multiple boards I would then need to add a CS pin.

Can I get away with just passing the MISO, MOSI, and SCK lines through the level shifter? Or do the RESET and CS pins also need to be stepped down from 5V as well? Could I just add some resistors for those 2 lines instead of using 2 level shifters?

I also looked at this similar question(Are the SPI pins 5V tolerant?) and am curious if I can just apply a voltage divider method(https://learn.sparkfun.com/tutorials/voltage-dividers/) to just the MISO line? All of the other lines in use are output pins from the Pi GPIO from what I understand.

I even thought the RESET pin might be a input but it must be configured as an output in the GPIO command line and written to 0 in order to reset the uno.

Thanks for any insight!

1
  • For any wires that go from the Arduino to the Pi, I would use a resistor divider. In any other case, 3.3v --> 5v device will work. Commented Sep 25, 2021 at 12:20

1 Answer 1

2

The Pi is a 3V3 device, most Arduinos are 5V.

It is not safe to feed a 5V signal into a Pi GPIO.

The Pi only works as a SPI bus master, it controls the clock.

This means that the SPI signals are:

  • Clock (SCLK) from Pi to Arduino.
  • Master Out Serial In (MOSI) from Pi to Arduino
  • Master In Serial Out (MISO) from Arduino to Pi
  • Chip Select (CS) from Pi to Arduino

The Arduino (whether 5V or 3V3) will be happy with the Pi's 3V3 signals.

The Pi will not be happy with a 5V Arduino's MISO signal.

So MISO is the only line which needs protection. I normally use a resistor divider to drop the Arduino 5V signal to a Pi safe 3V3 but you can use a level shifter chip if you prefer.

1
  • Thanks, Joan! I'm satisfied to proceed with this method. But for the sake of my understanding I'd like some clarification about the why the CS and Reset lines don't need the same protection. I get that they are configured as outputs from the pi, but in both cases to either reset the arduino or call the cs pin, the output value must be written to zero. This is where I think I had a misunderstanding, does the 0 on the output gpio pin not mean that it's pulling that line to GND? Or what is actually happening there if the current from the arduino CS/RST is not flowing through the Pi to GND?
    – AustinFoss
    Commented Sep 25, 2021 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.