Search code examples
arduinoavrdude

Using an Arduino Mega2560 as AVR programmer causes it to stop


I want to program an Atmega328 through a Arduino Mega2560. I have it connected as shown below:

Arduino Mega2560      Atmega328
  50 MISO ------------- 18 MISO
  51 MOSI ------------- 17 MOSI
  52 SCK -------------- 19 SCK
  53 SS --------------- 16 SS

  5V ------------------ 7 Vcc
  GND ----------------- 8 GND

Also, I loaded the ArduinoISP sketch (from the Examples in the IDE) into the Mega2560. Which seems to work, as I have a green LED flashing on pin 9 when it is running.

However, when I try to use the programmer with avrdude, I get this error:

bf@localhost:~$ avrdude -c arduino -p m328 -P /dev/ttyACM0 -b 19200 -U flash:r:test.hex:i
avrdude error: programmer is not responding
avrdude warning: attempt 1 of 10: not in sync: resp=0x00
avrdude error: programmer is not responding
avrdude warning: attempt 2 of 10: not in sync: resp=0x00
...
avrdude error: programmer is not responding
avrdude warning: attempt 10 of 10: not in sync: resp=0x00
avrdude error: unable to open port /dev/ttyACM0 for programmer arduino
avrdude error: avrdude built without libserialport support; please compile again with libserialport installed

avrdude done.  Thank you.

Also, the green LED stops flashing. This makes me think that avrdude is trying to program the Arduino, instead of communicating over the serial port to to Arduino. I have to reset the Arduino to get the green LED to start flashing again.

I am using /dev/ttyACM0 in both caes, could that collide in some way?

Update when I hit the Arduino's reset button while avrdude is trying to communicate, I get this error:

bf@localhost:~$ avrdude -c avrisp -p m328 -P /dev/ttyACM1 -b 19200 -U flash:r:test.hex:i
avrdude error: programmer is not responding
avrdude warning: attempt 1 of 10: not in sync: resp=0x00
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x000000 (retrying)
avrdude: device signature = 0x000000 (retrying)
avrdude: device signature = 0x000000
avrdude error: Yikes!  Invalid device signature.
avrdude error: expected signature for ATmega328 is 1E 95 14
        Double check connections and try again, or use -F to override
        this check.


avrdude done.  Thank you.

Solution

  • I gave up and bought a €15 Olimex programmer. Connected it, and it works.