avr dude and arduino as an ISP

I have an atmega328p set up on a bread board and trying to use my arduino as an ISP. I loaded the the arduino with the ISP sketch. Then hooked up:

Arduiono pin 11 to pin chip pin 17(MOSI), Arduino pin 12 to pin 18(MISO) and Arduino pin 13 to pin 19(SCK), and Arduino reset to pin 1. There is no crystal oscillator on the bread board (want to use the internal one).

Here is a copy of a portion of my makefile

MCU = atmega328p F_CPU = 1000000UL BAUD = 9600UL

Also try BAUD = 19200 or 38400 if you're feeling lucky.

A directory for common include files and the simple USART library.

If you move either the current folder or the Library folder, you'll

need to change this path to match.

LIBDIR = ../../AVR-Programming-Library

####------------------------------------------------------
#### Programmer Defaults
#### Set up once, then forget about it
#### (Can override. See bottom of file.)
####------------------------------------------------------

PROGRAMMER_TYPE = avrisp

extra arguments to avrdude: baud rate, chip type, -F flag, etc.

PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0

and here is the error I get

vrdude -c avrisp -p atmega328p -b 19200 -P /dev/ttyACM0 -U flash:w:blinkLED_AVR_style.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000 avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.

avrdude done. Thank you.

Makefile:130: recipe for target 'flash' failed make: *** Error 1 [/quote]

This chip is one I bought and loaded the arduino boot loader on it but decided to venture out side of arduino and deal more with more simplistic AVR programming.

mlmartinet: Arduino reset to pin 1.

Wrong. Unless you modified the ArduinoISP it should be Arduino pin 10 to reset pin on the target chip.

I suggest you get this working in the Arduino IDE before adding the extra complication of using the makefile.

OK fixed the pin issue and I am now attempting to up load via the arduino IDE as you recommended. Still no joy. I even went as far as putting a pull up resistor on pin 1 of the bread board chip and a 10nF capacitor between rest and ground on the arduino board.

avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.

looks like i am using version 1.0.5 and I am running linux mint.

I don't know if it's the cause of your problem but the 1.0.5 you're running is a very outdated and non-standard version of the Arduino IDE. The problem is the linux package manager doesn't have the latest versions due to licensing issues. I recommend you to download the latest version from: http://www.arduino.cc/en/Main/Software

That actually got me whole lot further I am now running the latest and greatest. Seems to only work with the 16Mhz crystal attached though. I guess I just need to setup the correct fuses?

That's correct. You will need to leave the crystal connected until you have changed the fuses to the internal oscillator. I like this fuse calculator: eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p If you want to use the Arduino IDE then I recommend this hardware package: https://github.com/MCUdude/MiniCore

I am trying to get away from the IDE and since I updated the IDE and used the newer I am assuming arduino as ISP sketch I have been doing my uploading throught the command line with the make flash with great success. I should be able to adjust my make file but it doesn't seem to change my fuses on the chip. I am setting the low fuse to 0x5F which gives me CKDIV8 and SUT1

Mega 48, 88, 168, 328 default values

LFUSE = 0x62 HFUSE = 0xdf EFUSE = 0x00

Generic

FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m

fuses: $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ $(PROGRAMMER_ARGS) $(FUSE_STRING) show_fuses: $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv

Called with no extra definitions, sets to defaults

set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m set_default_fuses: fuses

Set the fuse byte for full-speed mode

Note: can also be set in firmware for modern chips

set_fast_fuse: LFUSE = 0x5F set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m set_fast_fuse: fuses

Set the EESAVE fuse byte to preserve EEPROM across flashes

set_eeprom_save_fuse: HFUSE = 0xDF set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m set_eeprom_save_fuse: fuses

Clear the EESAVE fuse byte

clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m clear_eeprom_save_fuse: fuses

And this is what avr dude sends back:

avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

My understanding from: http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions is safemode prevents the fuses from changing. The strange thing is my reading of that indicates that safemode is on by default and must be disabled by the -u command line option or by setting default_safemode = no; in the configuration file but I don't see either of those things used by the Arduino IDE and it says nothing about safemode when I set fuses using Tools > Burn Bootloader

If you post the makefile command you're running, the AVRDUDE command the makefile generates, and the full AVRDUDE output maybe we can spot the problem.

Well I got it working by just running the commands through avrdude but I definitely would like to learn more about this make file. I understood most of it but couldn’t find out how to stop it from running safe mode.

##########------------------------------------------------------##########
########## Project-specific Details ##########
########## Check these every time you start a new project ##########
##########------------------------------------------------------##########

MCU = atmega328p
F_CPU = 1000000UL
BAUD = 9600UL

Also try BAUD = 19200 or 38400 if you’re feeling lucky.

A directory for common include files and the simple USART library.

If you move either the current folder or the Library folder, you’ll

need to change this path to match.

LIBDIR = …/…/AVR-Programming-Library

##########------------------------------------------------------##########
########## Programmer Defaults ##########
########## Set up once, then forget about it ##########
########## (Can override. See bottom of file.) ##########
##########------------------------------------------------------##########

PROGRAMMER_TYPE = avrisp

extra arguments to avrdude: baud rate, chip type, -F flag, etc.

PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0

##########------------------------------------------------------##########
########## Program Locations ##########
########## Won’t need to change if they’re in your PATH ##########
##########------------------------------------------------------##########

CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRSIZE = avr-size
AVRDUDE = avrdude

##########------------------------------------------------------##########
########## Makefile Magic! ##########
########## Summary: ##########
########## We want a .hex file ##########
########## Compile source files into .elf ##########
########## Convert .elf file into .hex ##########
########## You shouldn’t need to edit below. ##########
##########------------------------------------------------------##########

The name of your project (without the .c)

TARGET = blinkLED

Or name it automatically after the enclosing directory

TARGET = $(lastword $(subst /, ,$(CURDIR)))

Object files: will find all .c/.h files in current directory

and in LIBDIR. If you have any other (sub-)directories with code,

you can add them in to SOURCES below in the wildcard statement.

SOURCES=$(wildcard .c $(LIBDIR)/.c)
OBJECTS=$(SOURCES:.c=.o)
HEADERS=$(SOURCES:.c=.h)

Compilation options, type man avr-gcc if you’re curious.

CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR)
CFLAGS = -Os -g -std=gnu99 -Wall

Use short (8-bit) data types

CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums

Splits up object files per function

CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS = -Wl,-Map,$(TARGET).map

Optional, but often ends up with smaller code

LDFLAGS += -Wl,–gc-sections

Relax shrinks code even more, but makes disassembly messy

LDFLAGS += -Wl,–relax

LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf

LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf

TARGET_ARCH = -mmcu=$(MCU)

Explicit pattern rules:

To make .o files from .c files

%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<;

$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@

%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@

%.eeprom: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

%.lst: %.elf
$(OBJDUMP) -S $< > $@

These targets don’t have files named after them

.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses

all: $(TARGET).hex

debug:
@echo
@echo “Source files:” $(SOURCES)
@echo “MCU, F_CPU, BAUD:” $(MCU), $(F_CPU), $(BAUD)
@echo

Optionally create listing file from .elf

This creates approximate assembly-language equivalent of your code.

Useful for debugging time-sensitive bits,

or making sure the compiler does what you want.

disassemble: $(TARGET).lst

disasm: disassemble

Optionally show how big the resulting program is

size: $(TARGET).elf
$(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf

clean:
rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj
$(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst
$(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~
$(TARGET).eeprom

squeaky_clean:
rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom

##########------------------------------------------------------##########
########## Programmer-specific details ##########
########## Flashing code to AVR using avrdude ##########
##########------------------------------------------------------##########

flash: $(TARGET).hex
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<

An alias

program: flash

flash_eeprom: $(TARGET).eeprom
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<

avrdude_terminal:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt

If you’ve got multiple programmers that you use,

you can define them here so that it’s easy to switch.

To invoke, use something like make flash_arduinoISP

flash_usbtiny: PROGRAMMER_TYPE = usbtiny
flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments
flash_usbtiny: flash

flash_usbasp: PROGRAMMER_TYPE = usbasp
flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments
flash_usbasp: flash

flash_arduinoISP: PROGRAMMER_TYPE = avrisp
flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0

(for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5

flash_arduinoISP: flash

flash_109: PROGRAMMER_TYPE = avr109
flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0
flash_109: flash

##########------------------------------------------------------##########
########## Fuse settings and suitable defaults ##########
##########------------------------------------------------------##########

Mega 48, 88, 168, 328 default values

LFUSE = 0x62
HFUSE = 0xdf
EFUSE = 0x00

Generic

FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m

fuses:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU)
$(PROGRAMMER_ARGS) $(FUSE_STRING)
show_fuses:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv

Called with no extra definitions, sets to defaults

set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
set_default_fuses: fuses

Set the fuse byte for full-speed mode

Note: can also be set in firmware for modern chips

set_fast_fuse: LFUSE = 0xE2
set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m
set_fast_fuse: fuses

Set the EESAVE fuse byte to preserve EEPROM across flashes

set_eeprom_save_fuse: HFUSE = 0xD7
set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
set_eeprom_save_fuse: fuses

Clear the EESAVE fuse byte

clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
clear_eeprom_save_fuse: fuses