Search code examples
arduinomicrocontrolleravr

Can't program ATtiny2313a with Arduino. Is my chip bricked?


I've been trying to burn a program into ATtiny2313A-PU with my Arduino Uno R3 used as a programmer.

First I tried to program it from Arduino IDE 1.0.1 (Windows 7) and it seemed to upload the sketch, but the blink program didn't work. Then I found Michael Holachek's tutorial and followed his instructions:

  1. uploaded the ArduinoISP sketch to my Arduino Uno
  2. wired the circuit on a breadboard
  3. installed WinAVR on my Windows 7.
  4. downloaded Michael's template files (Makefile and main.c) and edited Makefile to match my settings (external 8 MHz crystal). I used this online fuse calculator to get correct fuse parameters.
  5. then, in cmd.exe, changed directory to the directory where I saved Makefile and main.c and ran 'make flash'

Makefile

DEVICE     = attiny2313a
CLOCK      = 8000000
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

File main.c

main.c

Below is the output I got:

C:\Users> cd /D D:\electronics

D:\electronics> cd nikon/mi

D:\electronics\nikon\mi> make flash

avr-gcc -Wall -Os -DF_CPU=8000000 -mmcu=attiny2313a -c main.c -o main.o
main.c:6: error: stray '\342' in program
main.c:6: error: stray '\200' in program
main.c:6: error: stray '\250' in program
main.c: In function 'main':
main.c:9: error: stray '\342' in program
main.c:9: error: stray '\200' in program
main.c:9: error: stray '\250' in program
make: *** [main.o] Error 1

I suspect that I might brick the fuses on ATtiny2313a. If that is the case, I think I will have to build this AVR rescue shield. Maybe the Makefile was configured incorrectly? How can I identify the problem? How can I check whether the chip is still alive?


Solution

  • You are getting compile errors there. I would check the contents of main.c for what the compiler is telling you to check. It looks like in the copy and paste of the code, something was lost. Also

    PORTD ^= (1 << PD6);  // toggle PD6
    

    can be replaced with

    PIND = (1 << PD6);   // or _BV(PD6), since you should be using avr-libc anyway.
    

    as per Atmel's datasheets.