Electronic – ATmega328p will not enter programming mode

atmega328praspberry pispi

schematic

simulate this circuit – Schematic created using CircuitLab

I'm trying to connect a ATmega328p and Raspberry Pi together, communicating via SPI. The Pi is Master and is used to program the ATmega when first connected, (ATmega is completely blank).

The ATmega will not respond to the programming mode command and I can't find why.

I have the Pi at 3.3V, and the ATmega at 5V (design does not allow for the ATmega to be run at 3.3v) with a 16Mhz crystal. They are connected via a txb0104 level shifter for the 4 SPI lines, and a pull-up resistor and transistor for the reset line.

Viewing the SPI inputs (+ reset) to the ATmega with an oscilloscope, I have Reset and SS going low, and SCK & MOSI clocking in the programming mode command (AC-53-00-00). I then receive no response from the MISO, and Pi is just attempts to send the programming mode command again after 10 seconds.

I have checked that the SPI lines are going to the correct pins, and any distortion from the level shifter seems negligible. I've also used an Arduino-as-isp to program a blank ATmega in the same setup, bypassing the level shifter so the Atmega should be setup correctly.

Is there anywhere I am likely going wrong here? Only thing I can think of is that my level shifter is unsuitable.

Best Answer

The transistor circuit at the RST input acts as an inverter. Is that what you want? In other words, the reset-pi pin would need to be specified to invert the reset signal.

Btw. 3.3V is at the low end of acceptable gate voltage for a 2n7000. With an npn transistor you'd have a more robust voltage margin.