Lock/Fuse Bits in AVR

علاء عجوه embedded systems 0 ﺗﻌﻠﻴﻘﺎﺕ
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

long time since my tutorial SD Card reader using arduino  is posted here, but i’m back with an article I hope to be interesting for the readers.

Every device we know has “configuration” to operate the way we want, for example the television is configured to work with the receiver , the computer is configured to work with a usb flash connected to it , and also every microcontroller has a configuration bits to work the way we want.

I’m going to talk about the AVR microcontrollers but the same concept works for another micorcontrollers

the AVR microcontrollers’ memory consists of :

1-FLASH section that contains code
2-SRAM section for the runtime variables
4- lock/fuse bits for storing the mcu configuration.

the lock/fuse bits consists of :

a. RSTDISBL : convert the reset pin into general purpose IO pin
b. DWEN : turns on DebugWire debug system. But DebugWire port is physically implemented on a reset pin, so enabling this bit have the same effect as previous
c. SPIEN : Enable Serial Program and Data Downloading.
d. CKSELn : affects system clock option.
e. WDTON : for the watchdog timer
f. BOOTRST : to start the code from the FLASH or from a bootloader.

these bits are between low fuse bits, high fuse bits and extended fuse bits. Low fuse bits determines things such as clock sources , startup time and brown out detector level. High fuse bits determines things such as if there’s a bootloader, boot block size … . Extended fuse bits determines if the watchdog timer is always on.

for the fuse bits of atmega328p , open the datasheet http://www.atmel.com/Images/doc8161.pdf  page 294 memory programming section.

for example, if we want to set our mcu to boot from bootloader, simply set the bit of the bootloader  bit0 at the high fuse bits  to zero
note: zero means programmed , one means unprogrammed  and so on

this process is done during flashing the hex file onto the mcu by using avrdude , here’s an example for this

avrdude -p m128 -u -U flash:w:diag.hex -U eeprom:w:eeprom.hex -U efuse:w:0xff:m -U hfuse:w:0x89:m -U lfuse:w:0x2e:m

-U” indicates a memory operation
w” indicates a write
m” take the immediate value specified on command line

the value in hex to be human readable.

the lock bits is used to provide some level of protection to the contents of the FLASH and EEPROM memories .
the following table will explain the level of protections : lock bit protection level.png

lock bits protection levels
note : DO NOT manipulate these bits unless you know what you’re doing , by these bits you can make magic and also can result into mcu failure.

in arduino there’s some sort of default values for these bits used when you buy a new mcu and you need to put it in your arduino board

for uno

Low Fuse 0xFF
High Fuse 0xDE
Extended Fuse 0×05

for mega

Low Fuse 0xFF
High Fuse 0xD8
Extended Fuse 0xFD

see you next time !



علاء عجوه

Engineering Student , Computer Science , Ahly , Manchester United , Comics @agwatic , http://www.facebook.com/agwatic ... That's it :D

ﺗﺎﺑﻌﻨﻲ اﻳﻀﺎً ﻋﻠﻲ

ﻣﻘﺎﻻﺕ ﺁﺧﺮﻱ ﻟﻲ