Friday 29 April 2011

Unlocking ATMEGA64 fuse bits

     I replaced an ATMEGA64 microcontroller with a new one. And I said that it would need a basic test program to run (blink a led on a certain pin). Although I had a 8 Mhz external crystal I observed that the LED was blinking slower than expected so I said to myself that it had to be something related to the fuse bits.

     After a small search on the web I found this AVR Fuse Calculator. And I played around with these fuse bits and also programmed them to my MCU and finally I ended up locking it.

I've set the fuse bits as followed: LOW: C0 HIGH: 99 EXTENDED: FF.

     So here's the solution for those interested or maybe for those experiencing the same problem:
     After some reading I understood that the fuse bits are low active. So I programmed my MCU (with CKSEL = 0000 and SUT = 00) to run on a external clock source that should be connected on pin XTAL1.
     And in order to unlock my ATMEGA64 I had to generate a square wave using another MCU (I chose an AMTEGA8) and to connect it to pin XTAL1 of my ATMEGA64 (do not remove your crystal or the caps) like so:

     Load the .hex file to ATMEGA8 after compiling this code:


int main()
{

DDRB = 0xFF;
while (1)
{

PORTB = ~PINB;
asm volatile("nop");
asm volatile("nop");
// _delay_ms(1000); // Uncomment this line to test flicker
}
return 0;
}


     By using this code it will generate on any pin of PORTB on ATMEGA8 a square wave with 1 MHz frequency. This will allow any of you to reprogram the fuse bits of your locked AVR microcontroller.

     In my case in order to make my ATMEGA64 to work properly I've chosen the following fuse bits: LOW: EE HIGH: 99 EXTENDED: FF.

Best of luck in unlocking your own microcontrollers.

No comments: