I have followed this demo and have set up a standalone ATmega328P being programmed from a Raspberry Pi via the SPI lines. I have also added a 16 MHz crystal with 22 pF capacitors, as well as I have enabled and set up I²C between the ATmega and Raspberry Pi.
I have compiled and uploaded a bunch of programs and I can confirm everything works as expected.
As you can imagine, it is quite hard debugging things without a serial connection, so I connected pin 2 of the ATmega to GPIO14 of the Raspberry Pi and pin 3 to GPIO15. At this point, when I try uploading a program, I get this:
$ avrdude -P /dev/spidev0.0 -c linuxspi -p m328p -U flash:w:build-uno/program.hex
avrdude: error: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
If I break the pin2 to GPIO14 connection, then my program gets uploaded. And if I restore the connection between the pins and open Minicom on the Raspberry Pi I see the output of my simple program:
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1000);
Serial.println("Echo Test");
}
$ minicom -b 9600 -o -D /dev/ttyS0
Welcome to minicom 2.7.1
OPTIONS: I18n
Compiled on Aug 13 2017, 15:25:34.
Port /dev/ttyS0, 16:50:17
Press CTRL-A Z for help on special keys
Echo Test
Echo Test
Echo Test
Echo Test
But whenever I press a button on the keyboard (inside Minicom), I notice that the ATmega gets reset. If I hold the button down the transmission of "Echo Test" seizes as it is getting reset rapidly.
How can I get serial to function properly?
Addendum:
I'm using a Raspberry Pi 4, and in raspi-config I have disabled serial login and left the serial hardware enabled.