2
votes

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 uploade the sketch, but the blink program didn't work. Then I found Michael Holachek's tutorial and followed his instructions:

  1. uploaded 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

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 Attiny 2313a. 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?

2
I don't see how a compiler error would have any relation to the chip being broken. Your code is broken instead.user529758

2 Answers

3
votes

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.

0
votes

well, I googled a little bit more and found that the most common solution, when chips are identical, but have different suffixes (like attiny2313 and attiny2313a) is to use -F key for overriding the signature check. So, I added the key in Makefile DEVICE = attiny2313 -F and my attiny2313a was programmed successfully! TRON, thanks for pointing me in the direction of main.c! Unfortunately I can't upvote your answer because my reputation is 11. I still wonder how those square characters could get there?