Electronic – Arduino as AVR Programmer with Avrdude

arduinoatmegaatmel-studioavrdudeisp

My objective is to program a single ATmega328P sitting on a breadboard. Due to my location and cash at hand I cannot acquire a AVR ICSP programmer so instead (through research) I found I can use a arduino as a AVR programmer and decided to use it.

The ArduinoISP sketch was uploaded to my Arduino Uno R3 successfully and the appropriate pins were hooked up to my breadboard.

I wrote a simple C program in Atmel Studio and compiled it to a intel hex file then proceeded to use avrdude to upload the file to the μCU. Avrdude reported a successful flash (verification successful as well) but the μCU doesn't seem to be responding.

The simple C program as below:

//Define CPU speed to 1 MHz (8 MHz internal with CKDIV8)
#define F_CPU 1000000

#include <avr/io.h>
#include <util/delay.h>

int main(void){
    DDRC = 0xFF; //Set all of port C to outputs

    while(1){
        PORTC = PORTC ^ 0xFF; //Toggle all of port C
        _delay_ms(500); //Delay 500ms
    }

    return 0;
}

Command used to send the flash to the Atmega328P:

$ avrdude -c arduino -p m328p -P COM9 -U flash:w:"compiled_file.hex":i

A single LED (with 220 ohm resistor) was hooked from ground to pin PC5. If my logic is correct this light should toggle on/off every 500ms but the light remains off. The LED has been tested and connection polarity confirmed (positive to pin, negative to ground).

As a side note, I also found that when I told avrdude to read the fuse settings on the μCU, they all registered to be 0x00, which is quite strange.

Any help would be much appreciated.

Update:

Through some experimentation I found that the command listed above was somehow telling avrdude to program the ATmega328P on the arduino uno itself rather than the ATmega328P on the breadboard. I've successfully reflashed the ArduinoISP to the Arduino so I'm back to step one. Does anyone know how to get avrdude to write to the ATmega328P on the breadboard?

Best Answer

Reading through the question, it sounds like you forgot one of the required components.

Running AVRDUDE will cause the host MCU to reset. In order to prevent this, you need to put a capacitor on the host's nRESET line to keep the voltage above a certain threshold. Add the capacitor as described in the ArduinoISP article and try again.