1

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Olexiy
  • 535
  • 1
  • 7
  • 14
  • 2
    I don't see how a compiler error would have any relation to the chip being broken. Your code is broken instead. –  Feb 18 '13 at 06:32
  • The link is (effectively) broken (it redirects to a generic page. And it seems to be completely empty). – Peter Mortensen Apr 27 '23 at 14:23
  • A direct analysis is: 342 200 250 (octal) → 0xE2 0x80 0xA8 (hexadecimal) → UTF-8 sequence for Unicode code point U+2028 ([LINE SEPARATOR](https://www.charset.org/utf-8/9)). LINE SEPARATOR is probably some representation of return/newline. The code was probably copied from the (now broken) web page. – Peter Mortensen Apr 27 '23 at 14:25
  • 1
    This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 27 '23 at 14:27
  • There are really two questions here. The stray character problem (resulting in the reported errors) and the rest (e.g., the title). It really ought to be two separate questions. – Peter Mortensen Apr 27 '23 at 14:39
  • Does this answer your question? [Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332/compilation-error-stray-302-in-program-etc) – TomServo Apr 30 '23 at 01:31

2 Answers2

3

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.

TRON
  • 46
  • 1
  • 1
    You are right, TRON. I found two strange characters in main.c (like unicode medium square symbol). I think they didn't let me copy the code of main.c to this forum correctly. I just could not get the right formatting. That's why the code wasn't added to my original question. – Olexiy Feb 18 '13 at 06:32
  • I will add a screenshot of main.c to the original post now. So, after those two characters were removed, the output changed very much. Now it seems to work, but there's another problem - avrdude can't find my chip 2313a in its configuration file. `avrdude: AVR Part "attiny2313a" not found.` I guess I will need to edit avrdude.conf. Am I correct? – Olexiy Feb 18 '13 at 06:40
0

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!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Olexiy
  • 535
  • 1
  • 7
  • 14