Professional Documents
Culture Documents
int main(void) {
DDRB = 0xFF;
while(1) {
PORTB ^= 0xFF;
this will toggle all the pins on PORTB as fast as possible (OK, modern AVR have a better mechanism where you write to PINB - but
I'll ignore that for the time being). Anyone of those PORTB pins (together with a common GND) can be connected to the AVR that
needs to be recovered.
5) "modern" AVRs have both a fuse and a pin called CLKOUT. By activating the CLKOUT fuse (be careful this time!) the CLKOUT pin
will produce full-swing signal at the CPU's clock frequency so even a brand new chip out of the packet can produce 1MHz this way
simply by activating (setting to 0) one fuse bit and applying power.
6) Use a frequency generator set to square wave and something around the 1MHz mark (could be faster if you like)
7)
If it's just a CKSEL "accident" this should have allowed you to fix the situation.
Another potential clock problem is where you attach a crystal (with caps), set the correct CKSEL fuses and it still will not oscillate this may be caused by not setting the CKOPT fuse (if the AVR has this) or selecting "Full swing" when the crystal is 8MHz or more.
This mode of operation uses more power (which is why it's not selected by default) but is required to get higher frequency crystals
to resonate correctly. If the AVR is in this situation the foregoing technique should also recover it.
Now some chips (mainly the lower pin count ones) have some more "dangerous" fuses that can make it seriously more difficult to
recover.
The chips that can be debugged with "debugWire" have a fuse called DWEN which is mutually exclusive with the SPIEN fuse (the
one that allows ISP to operate). If DWEN is set then the _RESET pin on the chip can no longer be used to invoke ISP and can only
be used for debugWire. When a chip is in this state you need a device that can do debugWire (Dragon, JTAGICEmkII, AVR One!) in
order to recover - you need to start debugging using debugWire then (with all the ISP wires attached) use the bottom entry on the
debug menu in AVR Studio 4 where there is an option to disable debugWire mode and this will reinstate ISP mode. If you don't have
a suitable device either find a friend who does or accept that the $2-$3 that the chip cost is less than the $50 that a Dragon will
cost and write this off to experience (it's a pretty fair bet you won't make this mistake again next time you program fuses!).
Perhaps the most insidious of all the fuses is the one found on low pin count AVRs called RSTDISBL. Because these AVRs have so
few pins they can sacrifice the use of the _RESET pin to be used (usually) as another GPIO pin instead. The problem is that ISP
works by holding the chip in reset and it does this by pulling the _RESET pin low. If that pin has now been disconnected from the
internal _RESET signal in favour of using it as an I/O then you simply cannot start ISP ever again in order to recover the situation.
If it is RSTDISBL that has been set then there IS a way back but for this you are going to need a device that can do High Voltage
programming. That basically means a Dragon, an STK500 or an STK600. For the very low pin count AVRs these can do HV Serial
Programming, while for the larger ones HV Parallel Programming is used. HVSP isn't TOO bad as it doesn't use many more pins than
ISP, but HVPP is a real problem as it uses the best part of 20 pins on the AVR. What's more both HVSP and HVPP actually work by
applying +12 Volts to the _RESET pin of the chip. Most circuits that the AVR has been designed into will not tolerate having 12V
applied in this way and could be damaged and if 20 pins are involved (often 20 out of 28 ) then it's very unlikely that the
surrounding circuitry has been designed to allow the intrusion of an HVPP programmer. So if you have set RSTDISBL and the chip is
not socketed so it can be lifted and placed in an HV programmer such as STK500/STK600 or even the small prototype area of a
Dragon then accept the fact that your $2-$3 chip is lost. Desolder it from the board and write this off to experience - you'll be more
careful programming fuses next time! ;-)
BTW, when using AVR Studio (4) as a programming tool it's very difficult to have a "fuse accident" in the first place. Other
programming tools make it less obvious what's actually being chosen so you may want to use this site:
http://www.engbedded.com/fusecalc/
which mimics the interface of AVR Studio to verify that you are selecting the right values. Note that fuses are ACTIVE LOW which
means you enable them when the bit is 0 and disable when the bit is 1. Rather confusingly some programming software (PonyProg)
even lets you switch whether a tick means "enabled" or "disabled". So be very cautious next time you set fuses. Measure twice, cut
once as the old saying goes and when using ISP software to changes fuses always do a read first, determine only those bits that
need to be changed, make that change then write back.
[this is just a "prototype" article - I welcome comments and feedback for improvements]