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.

  • \$\begingroup\$ Instead of describing the schematic, draw one, edit and Ctrl+M to use the embedded schematic drawing tool. Also attach the scope image if possible. \$\endgroup\$ – Bence Kaulics May 3 '17 at 13:32
  • \$\begingroup\$ What are you clocking it at during programming? \$\endgroup\$ – Matt Young May 3 '17 at 14:04
  • \$\begingroup\$ The SPI clock is 500 KHz \$\endgroup\$ – Snowsheer May 3 '17 at 14:25
  • \$\begingroup\$ Have you got any kind of gate biasing on the 2N7000? \$\endgroup\$ – user98663 May 3 '17 at 14:36
  • \$\begingroup\$ Gate is only connected to the 3.3V reset signal from the Pi \$\endgroup\$ – Snowsheer May 3 '17 at 14:44

What side of the voltage translator were you probing the MISO signal for a response from the Arduino?

According to your schematic, you have the 5V side on port A and the 3.3V side on port B. According to the datasheet for the TXB0104, this should be the other way around (5V actually exceeds the max rating for VCCA).

http://www.ti.com/lit/ds/symlink/txb0104.pdf (See sections 6.1 and 8.1)

This may be causing the output from the Arduino to not make it through the level shifter.

| improve this answer | |
  • 1
    \$\begingroup\$ I've got the A/B labels mixed up on schematic. Measuring on oscilloscope is showing the signals from the Pi pass through it (and get shifted correctly) \$\endgroup\$ – Snowsheer May 3 '17 at 16:08

How are you supplying the 5V for the atmega, with the RPi? I had a similar problem for programming a cortex-m0 chip using a raspberry.

I solved my problem by connecting the ground of the raspberry with the ground of the chip.

Hope it will help

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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