1

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.

4

There are two things wrong with the circuit in that demo.

  1. There is no decoupling capacitor on the power pins. This is required to keep the power stable during opertaion.
  2. More critically: this is being powered from 3.3V, but is being run at 16MHz. That is outside specifications. You should use an 8MHz crystal to operate at 3.3V.
  • Thanks for pointing out, I see now indeed it's unrelated. Upvoted yours, deleted mine. – Michel Keijzers Nov 17 '20 at 17:08
  • Here is another video from the same creator which shows it working at 3.3V. He is using /dev/ttyAMA0 which doesn't work in my case so something is different but I can't tell what. I'll try adding a 0.1uF capacitor on the input, see if that makes any difference. – php_nub_qq Nov 17 '20 at 17:10
  • It will work at 3.3V, but it won't be stable. The serial port name change is because of a different version of Pi being used. – Majenko Nov 17 '20 at 17:13
  • Well in my case it is not only unstable it plain doesn't work, guess I'll just call it unlucky then and stick to debugging through i2c until I can establish a better setup. Thank you! – php_nub_qq Nov 17 '20 at 17:15

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.