Fixing bad AVR Fuses

It’s pretty easy to make mistakes while programming an AVR’s fuses and making a mistake could seem to render your AVR unusable. Don’t give up, there are three main causes that could lead to this message from avrdude:
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

  1. Check the connections between your programmer and the AVR (perhaps one of the leads have fallen out or one of the solder joints are damaged)
  2. The clock fuses are set for a source you aren’t providing, for more information on fixing this read below
  3. The SPIEN (SPI enable) fuse has been unprogrammed, this means that you can no longer program with a standard serial programmer (such as a USBTinyISP), to fix this you need a high voltage parallel programmer, for example MightyOhm’s High Voltage Rescue Shield (an arduino is required) or the Atmel AVR Dragon

By obtaining an ATTiny13 (or a similar, cheap AVR) you can fix any clock settings. There are a few steps required to get this to work as your clock:

  1. Download and compile this program (which will create a square wave out of PB4, pin 3 of the ATTiny13), clock.S (you’ll need an AVR ASM compiler like AVRA and the include file for your AVR, you can download tn13def.inc for an ATTiny13) OR if you’re using an ATTiny13 you can download this precompiled clock.hex
  2. Burn the compiled clock.hex to the AVR, for example (for an ATTiny13, using a USBTinyISP):
    $ avrdude -p t13 -c usbtiny -U flash:w:clock.hex
  3. Unprogram the CKDIV8 fuse (increasing the outputted frequency by 8 times), for example (for an ATTiny13, using a USBTinyISP):
    $ avrdude -p t13 -c usbtiny -U lfuse:w:0x7a:m
  4. Connect PB4, pin 3 (or whatever you set the port to be in clock.S) of the clock AVR to the XTAL1 pin of the broken AVR
  5. Use a fuse calculator to calculate your fixed clock settings, type in the avrdude command to change the fuses and append -B 50, this’ll slow the clock period so that the AVR can keep up with the SCK clock (at avrdude’s default value of 10usec the clock generated by the ATTiny13 isn’t fast enough to allow the target AVR to receive instructions, a period of 50usec should be fine, but increasing it won’t hurt only cause it to program slower), for example (for an ATMega328P, using a USBTinyISP):
    $ avrdude -p m328p -c usbtiny -B 50 -U lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>