1

Today I finally managed to program attiny2313a via Arduino Uno. It was a test blink program. After it was uploaded I saw that the LED blinked with 8 seconds delays instead of 1 second, so I decided to change clock settings in Makefile and main.c and burn the chip again. so, I only changed 8000000 to 1000000 in both Makefile and main.c and ran make flash in cmd (windows shell). Below is the output:

avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=attiny2313 -F -c main.c -o main.o
cc1.exe: error: avr25: No such file or directory
make: *** [main.o] Error 1

Why am I getting this error? Why was I able to compile and burn the program only once? I did not remove nor add nothing new. Actually I did not touch nothing except those clock settings. But even when I returned back to original settings (8000000) I still got the same error.

my Makefile

DEVICE     = attiny2313 -F
CLOCK      = 1000000
PROGRAMMER = -c arduino -P COM5 -b 19200 
OBJECTS    = main.o
FUSES      = -U lfuse:w:0x5e:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m


######################################################################
######################################################################

# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:    main.hex

.c.o:
    $(COMPILE) -c $< -o $@

.S.o:
    $(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
    $(COMPILE) -S $< -o $@

flash:  all
    $(AVRDUDE) -U flash:w:main.hex:i

fuse:
    $(AVRDUDE) $(FUSES)

install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
    bootloadHID main.hex

clean:
    rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
    $(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
    rm -f main.hex
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm: main.elf
    avr-objdump -d main.elf

cpp:
    $(COMPILE) -E main.c

my main.c

#define F_CPU 1000000  // CPU frequency for proper time calculation in delay function

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

int main (void){
    DDRD |= (1 << PD6);  // make PD6 an output

    for(;;){
        PORTD ^= (1 << PD6);  // toggle PD6
        _delay_ms(1000);  // delay for a second
    }

    return 0;  // the program executed successfully
}
Olexiy
  • 535
  • 1
  • 7
  • 14

2 Answers2

1

It turns out that the reason was in the "-F" key that was added in Makefile to make avrdude think that attiny2313a was actually an attiny2313 (overriding signature check). It is strange but the "-F" key has to be removed after the first programming of the chip. I guess this also applies to other newer modifications of AVR chips that are identical to their base (ar parent?) modifications but have various suffixes added to their names (like 'attiny2313a' or 'atmega168p')

So. when a microcontroller is programmed for the first time, and avrdude doesn't recognise the chip, the -F key should be added after the name of the chip:

DEVICE = attiny2313 -F

but, after the chip is programmed for the first time, that -F key has to be removed, otherwise it will not be possible to program the chip again.

Olexiy
  • 535
  • 1
  • 7
  • 14
1

Please, please, for the good of the chip, do not use -F on avrdude.

The reason you are having issues programming your tinyAVR is because you are feeding avrdude the wrong part number. The correct argument to programm the ATtiny2313 is -pt2313 [or just use part t2313]. Using -F can go on to brick your chip, especially since you are feeding it fuses [bricked chips may in some instances be recovered by using a high voltage programmer, depending on what fuse settings were tossed at it].

For more information on avrdude, read its manual page

       -p partno
               This is the only option that is mandatory for every invocation of avrdude.  It specifies the type of the MCU connected to the program‐
               mer.  These are read from the config file.  If avrdude does not know about a part that you have, simply add it to the config file (be
               sure and submit a patch back to the author so that it can be incorporated for the next version).  See the sample config file for the
               format.  Currently, the following MCU types are understood:

               Option tag   Official part name
               ...snip...
               t2313        ATtiny2313
               ...snip...

The device signatures for the ATtiny2313 and the ATtiny2313A are the same, but avrdude claims not to talk to the 2313A. Disable fuse programming if you do not need them and test it out without the -F option. Cheers.

PS. The reason gcc is faulting on you is because

   -Fdir
       Add the framework directory dir to the head of the list of directories to be searched for header files.  These directories are interleaved with
       those specified by -I options and are scanned in a left-to-right order.

You are passing it an argument it doesn't know what to do with it. To fix this stuff, on your Makefile, add

PROGDEV=t2313

and change your avrdude invocation to use PROGDEV instead of DEVICE.

Also, as stated on a previous answer

PORTD ^= (1 << PD6);

can be replaced by

PIND = (1 << PD6);

the latter compiles to just one instruction, compared to two three instructions as you have it. This saves on code space on your chip and makes the code run faster. See Atmel's datasheet for details.

TRON
  • 331
  • 1
  • 4