# Can I program 5V ATmega328P using 3.3V ICSP bus?

I am considering building a microcontroller HAT for Raspberry Pi Model B+. Since the Pi have the SPI bus exposed and some avrdude fork supports using it directly, I am hoping that my HAT can allow Raspberry Pi talk to the ATmega328P using SPI ICSP for flashing the chip instead of using serial and some serial bootloader. However the pins should be disengaged from the Pi when not required so that other SPI peripherals can be connected to both devices too. Similar situation exists for I2C, UART buses and one GPIO pin. All pin dis/engaging is done using one PCF8574 chip on Pi's I2C bus.

I know very well that I can run the ATmega328P at 3.3V, possibly overclock it to 16MHz, but I am asking about doing this with the microcontroller running at 5V. At 3.3V disengaging the pins requires just some CD4066s

• I think it is possible, normal Tx / Rx communication normally works also with a 3.3V device and a 5V microcontroller (ofc I had a voltage devider from 5V to 3.3V), so why can't the SPI part do it. 3.3V is probably high enough for the microcontroller to give a High state. – T J Nov 11 '14 at 8:44
• How will the AVR be powered while it is being programmed? – Ignacio Vazquez-Abrams Nov 11 '14 at 23:56
• @IgnacioVazquez-Abrams The AVR is powered from the Pi's 5V rail. – Maxthon Chan Nov 12 '14 at 12:14

## 2 Answers

This should work fine. As long as the 3.3v high level is high enough to register as a high level on the AVR, this should work correctly.

You should also add series resistors for current limiting so that the 5v level from the AVR pins do not damage the input on the SoC.

• No. The MISO line will be driven too high by the 5v ATMEGA. – Chris Stratton Nov 11 '14 at 14:18
• The unidirectional level translating can be done using some 74LVC1G07's or 74LVC1T245's. – Maxthon Chan Nov 12 '14 at 15:05

The pi will probably be fried because the MOSI pin will is driven by the Arduino. If you want to use the pi as your ICSP, you will need a level shifter such as this one.

• Note I also need to disengage the pins when not used. Disengage, read tri-state. – Maxthon Chan Nov 12 '14 at 12:16