Sunday, May 17, 2015

Reset clock fuse bit on AVR

My ATTiny13A LED’s still blinking, but I can’t program it anymore.



Here's the message

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -n

avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -n -F

avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATtiny13 is 1E 90 07

avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ 

It can still be programmed using -B4 option however

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -B4 -n  

avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9007

avrdude: safemode: Fuses OK (H:FF, E:FF, L:6A)

avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ 


From evilmadscientist.com, it apparently my ATTiny clock is slower than my USBASP. We have to erase the chip and reset the clock.

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -tuF   

avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATtiny13 is 1E 90 07
avrdude> sck 1000
>>> sck 1000 
avrdude: set SCK frequency to 1000 Hz
avrdude> e
>>> e 
avrdude: erasing chip
avrdude: error: programm enable: target doesn't answer. 1 
avrdude> sck 10
>>> sck 10 
avrdude: set SCK frequency to 93750 Hz
avrdude> quit
>>> quit 

avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -n

avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -B4 -n 

avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9007

avrdude: safemode: Fuses OK (H:FF, E:FF, L:6A)

avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -B4 -tuF

avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9007
avrdude> sck 1000
>>> sck 1000 
avrdude: set SCK frequency to 1000 Hz
avrdude> e
>>> e 
avrdude: erasing chip
avrdude: set SCK frequency to 187500 Hz
avrdude> quit
>>> quit 

avrdude done.  Thank you.

Nugrohos-MacBook-Air:~ nugroho$

Nugrohos-MacBook-Air:~ nugroho$ avrdude -p t13 -c usbasp -P usb -U lfuse:w:0x6A:m -U hfuse:w:0xFF:m -B250



avrdude: set SCK frequency to 4000 Hz

avrdude: AVR device initialized and ready to accept instructions



Reading | ################################################## | 100% 0.03s



avrdude: Device signature = 0x1e9007

avrdude: reading input file "0x6A"

avrdude: writing lfuse (1 bytes):



Writing | ################################################## | 100% 0.01s



avrdude: 1 bytes of lfuse written

avrdude: verifying lfuse memory against 0x6A:

avrdude: load data lfuse data from input file 0x6A:

avrdude: input file 0x6A contains 1 bytes

avrdude: reading on-chip lfuse data:



Reading | ################################################## | 100% 0.01s



avrdude: verifying ...

avrdude: 1 bytes of lfuse verified

avrdude: reading input file "0xFF"

avrdude: writing hfuse (1 bytes):



Writing | ################################################## | 100% 0.01s



avrdude: 1 bytes of hfuse written

avrdude: verifying hfuse memory against 0xFF:

avrdude: load data hfuse data from input file 0xFF:

avrdude: input file 0xFF contains 1 bytes

avrdude: reading on-chip hfuse data:



Reading | ################################################## | 100% 0.01s



avrdude: verifying ...

avrdude: 1 bytes of hfuse verified



avrdude: safemode: Fuses OK (H:FF, E:FF, L:6A)



avrdude done.  Thank you.



Nugrohos-MacBook-Air:~ nugroho$ 

...

It’s bit different than on http://www.evilmadscientist.com/2007/fixing-a-bad-frequency-fuse-bit-on-an-avr/ because the Attiny13A clock automatically back to 187500 without manual set.



########


Untuk “menghidupkan” lagi AVR yang bermasalah dengan fuse-bit (mungkin kita tidak sengaja mensetting clock terlalu lambat, lebih lambat dari clock USBASP atau ISP kita sehingga program tidak dapat diupload), kita harus menghapus program yang terupload di AVR.

Gunakan avrdude dalam mode interaktif seperti di atas