This is a quick note on AVR programming with the AVRISP MkII programmer, with which it is possible to foul up your clock fuse bits. =)
(This might be plain as day to some out there, but *I* didn’t know about it, so I thought I’d jot it down.)
Minor problem: I was programming some AVRs when I thought I might try to change the clock fuse bits to use one of the low-frequency internal oscillators. Apparently, it is possible to change the clock frequency low enough that the ISP interface can no longer program the flash– at which point it *seems* as though the chip is lost. These are inexpensive chips, (around $2 each), but the cost can add up quickly if you don’t fix the broken ones. Besides, they’re made of plastic, so you can’t even recycle them into a trivet.
Here’s the trick, which is hinted at in the users guide: While the programmer can only write to flash above a certain speed, it can erase the chip almost at zero speed.
Previously, we discussed programming AVR microcontrollers with AVRdude, the cross-platform “AVR Downloader/UploaDEr.” Our setup uses a Mac, the AVRISP MkII programmer, and an ATtiny2313 chip. However, the basic problem and solution that we are describing here are applicable to setups with other computer platforms and AVR microcontrollers. (Presumably, there are similar issues that can also occur with other programmers.)
So, let’s assume that you’ve set your AVR clock source to a very slow internal signal, and you can no longer program the device by conventional means. It is still possible at that point to use avrdude in interactive mode by entering a command like the following:
avrdude -p t2313 -c avrispmkII -P usb -tuF
where “t2313,” “usb,” and “avrispmkII” should be changed as needed to reflect your device, interface/programmer location, and programmer.
Once it (finally) enters interactive mode (at its super-slow clock speed), enter “sck 1000” at the prompt. This slows down the serial communication greatly by setting the SCK signal period to 1000 microseconds. You can then erase the chip by entering “e” and then set the programmer back to normal by entering “sck 10” (for a 10 microsecond period). Finally, enter “quit” to exit interactive mode. Your chip should be back to normal at this point, which you can verify by programming it again– hopefully without the same fuse bit settings.