Electronic – Problems Re-Flashing ATtiny85 After Setting prescale to 0x00

attinyavrmicrocontroller

After flashing the ATtiny85 with code including setting the clock prescale to 0x00 (in code, not flashing the fuse), the next time I try and flash I get the following errors preventing me from doing so:

avrdude.exe: error: programm enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
avrdude.exe: AVR device initialized and ready to accept instructions
avrdude.exe: Device signature = 0x500075 
avrdude.exe: Expected signature for ATtiny85 is 1E 93 0B

I really don't understand. Obviously the USBasp is connected correctly and working (otherwise I would not get the "AVR device initialized…" trace line. I have tried re-flashing code that I was running (CLKPR = 0x00). Then tried flashing a simple blink program (no prescale), still failed. Then tried the blink program on a different ATtiny85 – worked. Back to the original, still can't flash!!!

I tried resetting the fuse using the -B1 to -B6, nothing…

I am very much a novice, so there is probably something stupid that I am doing!


Resetting that device just before I sent the flash sees to work. However, I now appear to have a new problem when trying to flash the fused back to default!

The command that I am issuing…

avrdude  -p t85 -P COM3  -b 19200 -c avrisp  -U efuse:w::m -v -B700

The output…

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.06s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.06s

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

After reading round, I am pretty sure that it is clock / crystal related. I am just not too sure how to go about adding a crystal.

Thanks again,
Harold Clements

Best Answer

There are several issues with the avrdude command you posted.

  • You are specifying a baud rate and a serial port with -P COM3 -b 19200, which is nonsensical as the USBasp is a pure usb peripheral and does not require a serial port nor use a usb to serial converter internally. These settings have no effect.

  • You have selected the Atmel avrisp as your programmer with -c avrisp, while you claim that your programmer is the USBasp. This may or may not work, but avrdude supports USBasp natively, so you should instruct avrdude that the programmer is USBasp with -c usbasp.

  • You are rewriting the efuse bits without specifying a value with -U efuse:w::m. The correct way to set the fuse bits in immediate mode (not reading the fuse bit values from a file) would be -U FUSE:w:VALUE:m, for example -U efuse:w:0xFF:m. The manual of avrdude does not state that leaving the fuse value unspecified sets the fuse to its default value, so it probably just sets the fuse to 0x00.

  • Your programmer is not the Atmel JTAG ICE, so the bit clock setting -B700 is nonsensical, and has no effect.

The good news is that you trashed efuse instead of hfuse, which could have bricked the AVR by setting RSTDISBL and thus preventing reprogramming.

To resurrect your chip, I would suggest to reprogram all fuses. My guess is that you have inadvertently messed up the fuse values at some point, causing the chip to run at 1MHz or less. This causes the programmer to communicate too fast relative to the clock frequency of the ATtiny, resulting in the glitched transaction you see. The USBasp has a jumper for lowering the data rate, which you should set. For the fuses themselves, there is a handy online tool for easily determining and understanding the values. To program the fuses, run

avrdude -p t85 -c usbasp -P usb -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m

(8MHz clock frequency using internal oscillator, isp enabled, no special settings)

For flashing the chip with a new .hex, run

avrdude -p t85 -c usbasb -P usb -U flash:w:FILENAME:i