What is Fuse Bit & Lock Bits in AVR Microcontroller?

AVR Lockbit & fusebit Fuse Bits and Lock Bits in AVR Microcontrollers Explained (Beginner-Friendly Guide)

A Complete Guide to AVR Fuse Bits and Lock Bits for Microcontroller Users

Learn what Fuse Bits and Lock Bits are in AVR microcontrollers, how they control clock settings, bootloaders, and memory protection, and how to safely program them without bricking your AVR. A complete beginner-friendly guide for ATmega and ATtiny users.

Introduction

AVR microcontrollers, such as the ATmega and ATTiny series, offer powerful configuration options that control how the chip behaves at startup, how memory is protected, and how programming interfaces operate. Two of the most important configuration features are Fuse Bits and Lock Bits. Although they sound similar, they serve completely different purposes.

The fuse bit is a unique feature of ATMEL's AVR microcontroller. There are some fuse bits with specific meanings inside each type of AVR microcontroller, and their characteristics are EEPROM that can be erased and written multiple times. By configuring (programming) these fuse bits, the user can set some characteristics, parameters and I/O configuration of the AVR fixedly, and of course, it also includes the locking (encryption) of the running code on the chip. Fuses are an extremely important part programming a chip, but are rarely explained thoroughly. You only need to set them once, but if you don't do it right, it's a disaster!

In this blog, you will learn what fuse bits are, why they matter, how lock bits protect your code, and how to safely program them without bricking your AVR.

🔍 What Are Fuse Bits in AVR?

You already know that an AVR microcontroller contains Flash, EEPROM, and RAM. But there is another small section of non-volatile memory—just 3 bytes—called fuse bits. These fuse bytes store permanent configuration settings that remain unchanged even when the power is off, yet you can rewrite them as many times as needed.Fuse bits control how the microcontroller behaves: whether it uses a bootloader, what clock source it runs from, startup timing, voltage requirements, and various hardware features. Despite the name, these “fuses” are not physical burnable fuses like the ones in household circuits—they are fully reprogrammable.

Beginners are often confused by fuse settings because AVR chips rely on them to define the clock, startup behavior, bootloader area, and important security options. Understanding these fuse bits is essential, especially when optimizing the MCU for lower power consumption or enabling specific functions.

Fuse Bits are special non-volatile configuration settings stored inside the AVR microcontroller. These settings determine how the MCU operates at a fundamental level — including:

AVR Fuse bits

🧩 Types of Fuse Bits

Most AVR microcontrollers use these fuse categories:

1. Low Fuse (LFUSE)

  • Clock source
  • Clock startup time
  • Watchdog settings

2. High Fuse (HFUSE)

  • Boot section size
  • BOOTRST (Enable bootloader at reset)
  • JTAG enable
  • EEPROM preserve on chip erase

3. Extended Fuse (EFUSE)

  • Brown-Out detection voltage
  • Clock startup time
  • Some advanced features depending on the model

🧩 Application of LOW Fuse Bits

1Clock selection : CKSEL0,CKSEL1,CKSEL2,CKSEL3

The first option is how the chip is clocked. Every CPU uses a clock, The clock keeps track of time for the chip, in general one assembly code instruction is run every clock cycle.

  • External Clock:means that a square wave is being input into the CLOCK-IN pin by using a clock generating chip. This is uncommon and usually you won’t be needing it.
  • Internal Clock :sets the avr to use the internal oscillator that is not very precise but good for most projects that don’t have fine timing requirements. You should know that this clock varies with temperature and the power supply voltage. You can chose from a 8MHz, 4MHz or 128KHz clock. The 128KHz clock is for very low power applications where the low speed helps conserve power. By using the internal clock, you don’t need to wire up a crystal so we can use the XTAL1 and XTAL2 pins for various other purposes.
  • External Crystal : option is used when you need a special clock rate, like 8MHz or 12MHz or a high precision clock that will not vary with temperature or power supply voltage fluctuations. In this case you need to connect an external crystal or oscillator.
Clock Selection Fuse bits

The Clock Source can be either of the following:

External Clock, Internal 8MHz clock, Internal 4MHz clock, Internal 128KHz clock, External Crystal (0.4-0.9 MHz), External Crystal (0.9MHz - 3.0MHz), External Crystal (3.0MHz - 8.0MHz) or External Crystal (8.0MHz +)

2Select Start Up Time : SUT0, SUT1

Fuse bits SUT0 and SUT1 are part of the Start-Up Time (SUT) configuration in AVR microcontrollers. These bits determine how long the MCU waits before starting program execution after power is applied or after a reset.

This delay is important because the clock source (especially crystals) needs time to stabilize. If the clock is not stable, the microcontroller may start incorrectly or behave unpredictably.

SUT0 and SUT1 select startup delay based on: Type of clock source (internal RC, external crystal, external clock),Required stabilization time,Power stability conditions

By default, chips that come from the factory have the Internal 8 MHz clock with 14CK + 65ms Startup.

They provide extra delays such as: 0 ms, 4.1 ms, 65 ms, Or longer, depending on clock mode

Note: Fuse bits are usually active low, meaning:
  • 0 = programmed (ON)
  • 1 = unprogrammed (OFF)

🧩 SUT Bit Settings (Example for ATmega Series)

Below is a typical table (actual values depend on the MCU model):

SUT0 SUT1 Startup Delay Purpose
0 0 Fast startup (minimal delay)
1 0 Moderate delay (some stabilization)
0 1 Longer delay (for slow-rising VCC)
1 1 Maximum delay (best for crystal stability & slow VCC)

📝 Example Fuse Setting

For an ATmega328P using an external 16 MHz crystal:

  • Clock Source: Full Swing Crystal
  • Recommended SUT: 65 ms (SUT1 = 1, SUT0 = 1)

This ensures the crystal is fully stable before code starts.

3system clock signal: CKOUT

CKOUT is a fuse bit that, when enabled, makes the AVR microcontroller output its system clock signal on the CLKO pin (usually PB0 or another alternate pin depending on the AVR model).

In simple terms:

  • 👉 CKOUT = Output the MCU clock to an external pin
  • 👉 This pin will output the same clock the MCU is using internally

When CKOUT is enabled, the microcontroller shares its internal or external clock with other devices.

🔌 How to Enable CKOUT (AVRDUDE Example)

Example for ATmega328P: (Where CKOUT = 0 to enable)


     avrdude -c usbasp -p m328p -U hfuse:w:0xDF:m
     

(available for some AVRs only) produces a square wave of the same frequency of the clock input (internal, external, crystal, etc) on a given pin (D2, B0, etc). This is useful if you’re debugging the clock rate, or if you want to use the clock to drive another chip.

4CLOCK DIVIDE : CKDIV8

CKDIV8 is a fuse bit that lets the AVR microcontroller run at 1/8 of its normal speed. It is enabled by default so the chip runs slower and safely. To run the MCU at full speed, disable CKDIV8.

(available for some AVRs only), causes the chip to divide the clock rate by 8. So if the clock source is set to Internal 8MHz and you have this fuse set, then you’ll really be running at 1MHz. By default, this is turned on.

CKDIV8 is a fuse bit that controls whether the AVR microcontroller divides its system clock by 8 before using it internally.In simple terms:

  • 👉 CKDIV8 = Clock Divide by 8
  • 👉 When enabled, the MCU runs at 1/8 of the selected clock frequency
  • 👉 When disabled, the MCU runs at the full clock speed

📌 Why CKDIV8 Exists

AVR chips are shipped from the factory with CKDIV8 enabled by default, which gives:

  • Lower power consumption
  • More stable startup
  • Compatibility with slow hardware

This is especially important when using the internal 8 MHz oscillator:

  1. With CKDIV8 → MCU clock = 1 MHz
  2. Without CKDIV8 → MCU clock = 8 MHz

This avoids unexpected fast operation for beginners and ensures safe operation on low-voltage power sources.

🧩 Application of HIGH Fuse Bits

1Reset Disable : BOOTRST

BOOTRST is a fuse bit that controls where the AVR microcontroller starts executing code after a reset.At the start of the Bootloader Section, or At the start of the Application Section (0x0000 address)

In simple words:

  • 👉 BOOTRST = Start program from the bootloader
  • 👉 BOOTRST unprogrammed = Start program normally from address 0x0000

This fuse turns the Reset pin into a normal pin instead of a special pin. If you turn this fuse on you cant program the chip using ISP anymore. I would suggest you never set this fuse unless you really mean to.By default, chips that come from the factory have this turned off (that is, Reset is enabled)

2Boot Size Fuses : BOOTSZ0,BOOTSZ1

In AVR microcontrollers, the Boot Size Fuse Bits — BOOTSZ0 and BOOTSZ1 — control how much Flash memory is reserved for the bootloader section. This area is used for tasks like firmware updates, USB bootloading, or serial programming.These fuse bits determine the size of the bootloader block and where the main application code begins.

Boot Size Options (Common AVR Models)

BOOTSZ1 BOOTSZ0 Bootloader Size
1 1 1 KB
1 0 2 KB
0 1 4 KB
0 0 8 KB

BOOTSZ0 and BOOTSZ1 let you choose how big your bootloader should be. A smaller bootloader gives you more program space, while a larger bootloader supports more advanced update features.

3 Preserve EEPROM memory through the Chip Erase cycle : EESAVE

The EESAVE fuse bit in AVR microcontrollers controls whether the EEPROM memory is erased during a Chip Erase operation. By default, when you erase or reprogram the chip, both Flash and EEPROM are cleared. Enabling EESAVE allows you to keep your stored data safe while updating firmware.

🔧 What EESAVE Does

  • EESAVE = 1 (unprogrammed) → EEPROM will be erased during Chip Erase
  • EESAVE = 0 (programmed) → EEPROM is preserved, even when you erase Flash

This fuse is extremely useful when your project stores important data, such as:Calibration values,Sensor offsets,Device configuration,User settings,Runtime logs,erial numbers or IDs.If EESAVE is programmed, these values remain intact even when updating or reflashing the firmware.

4 Watchdog timer always on: WDTON

The WDTON fuse bit in AVR microcontrollers controls whether the Watchdog Timer (WDT) is permanently enabled. Normally, the watchdog can be turned on or off through software, but when the WDTON fuse is programmed, the watchdog becomes always active, regardless of firmware settings.

🔧 What WDTON Does

  • WDTON = 1 (unprogrammed) → Watchdog can be enabled or disabled by software
  • WDTON = 0 (programmed) → Watchdog Timer is always on, cannot be turned off by code

Because AVR fuses are active low, setting WDTON to 0 forces the watchdog to run continuously.

📌 Why Use WDTON?

This fuse is commonly used in applications where maximum system reliability is required. If the program hangs, crashes, or gets stuck, the watchdog will reset the microcontroller automatically.Perfect for:Industrial control systems,Safety-critical devices,Remote or unattended equipment,Battery-powered sensors,Wireless nodes (LoRa, Zigbee, etc.)

5 Serial program downloading (SPI) enabled : SPIEN

The SPIEN fuse bit in AVR microcontrollers controls whether the chip can be programmed using the SPI (Serial Peripheral Interface). This is the standard method used by AVR programmers such as USBasp, AVRISP mkII, and Arduino-as-ISP.

When SPIEN is enabled, the microcontroller’s MOSI, MISO, SCK, and RESET pins are used for In-System Programming (ISP), allowing you to upload firmware without removing the chip from the circuit.

🔧 What SPIEN Does

  • SPIEN = 1 (unprogrammed) → SPI programming is disabled
  • SPIEN = 0 (programmed) → SPI programming is enabled

Without SPIEN enabled, you cannot program the AVR via ISP. This means tools like USBasp or Arduino-ISP will fail to communicate with the chip. It is enabled by default from the factory so developers can easily upload the first firmware

⚠ Warning:

If you disable SPIEN, you will need a High-Voltage Programmer (HVPP/HVSP) to re-enable programming. ISP will no longer work.

6 Debug wire Enable : DWEN

The DWEN fuse bit enables the debugWIRE interface on AVR microcontrollers that have limited pins. debugWIRE is a lightweight, single-wire debugging protocol that uses the RESET pin for debugging instead of multiple JTAG lines. It allows you to step through code, set breakpoints, inspect registers, and debug your program directly on the chip.

The DWEN fuse bit enables the debugWIRE interface on AVR microcontrollers that have limited pins. debugWIRE is a lightweight, single-wire debugging protocol that uses the RESET pin for debugging instead of multiple JTAG lines. It allows you to step through code, set breakpoints, inspect registers, and debug your program directly on the chip.

🔧 What DWEN Does

  • DWEN = 1 (unprogrammed) → debugWIRE is disabled
  • DWEN = 0 (programmed) → debugWIRE is enabled, RESET pin becomes a debug interface

⚠ Warnings

1. ISP Programming Disabled Temporarily: When debugWIRE is active, ISP (SPI programming) does not work because the RESET pin is busy with debugWIRE.
2. You Must Disable debugWIRE Before Leaving Debugging Mode To return to normal operation and allow ISP programming again:Use your IDE,Choose "Disable debugWIRE and Close".This restores the RESET pin and automatically clears the DWEN fuse.
3. Forgetting to Disable It: If you leave DWEN enabled and exit debugging incorrectly, you may need:A High-Voltage Programmer (HVPP/HVSP) to recover the chip.

5 External RESET Disable : RSTDISBL

The RSTDISBL fuse bit controls whether the AVR microcontroller’s RESET pin works as a normal reset input or is converted into a regular GPIO pin. This fuse is useful when you need extra I/O pins, especially on small ATtiny devices with limited pin count.

🔧 What RSTDISBL Does

  • RSTDISBL = 1 (unprogrammed) → RESET pin works normally
  • RSTDISBL = 0 (programmed) → External RESET function is disabled, pin becomes a GPIO

Enabling this fuse gives you one extra I/O pin, which can be valuable on small chips like ATtiny13, ATtiny85, etc.,

⚠ Warning:

Once RSTDISBL is enabled:❌ ISP Programming Will No Longer Work.ISP (In-System Programming) requires the RESET pin to enter programming mode. If RESET is disabled, standard programmers (USBasp, AVRISP, Arduino-ISP) cannot access the chip.You have access to a high-voltage programmer for o force the chip into programming mode and restore the RESET pin.

🧩 Application of Extended Fuse Bits

BODLEVEL (Brown-Out Detector Level)

The BODLEVEL bits inside the extended fuse control the minimum safe voltage required for the microcontroller to run. If the supply voltage drops below the selected threshold, the MCU resets to prevent unstable behavior.

Common BODLEVEL Settings

BODLEVEL2 BODLEVEL1 BODLEVEL0 BOD Voltage Description
1 1 1 Disabled BOD off (max power saving)
1 1 0 1.8V Safe for low-voltage operation
1 0 1 2.7V Good for battery-powered devices
0 0 0 4.3V For 5V systems

✔ Benefits of Correct Extended Fuse Configuration

  • Prevents code corruption during voltage drops
  • Ensures safe startup and shutdown
  • Improves reliability in industrial and outdoor applications
  • Saves power when BOD is disabled on low-power devices

🧩 Application of Lock Bits

Lock Bits in AVR microcontrollers are special protection settings that control whether the Flash memory and bootloader can be read or written. They help secure your firmware from unauthorized copying and prevent accidental overwriting during program updates.

The lock bits are stored separately from the fuse bytes and provide multiple levels of protection depending on your application needs.

🔐 What Are AVR Lock Bits?

AVR microcontrollers include two lock bits (LB1 and LB2) and bootloader protection bits (BLBxx). These bits determine:

  • Whether the Flash program memory can be read
  • Whether the Flash memory can be written or erased
  • Whether the bootloader can modify application code
  • Whether the application can modify bootloader code

Like most AVR bits, lock bits are active low:

  • 0 = protection enabled
  • 1 = unprotected

🧩 1. Lock Bits (LB1, LB2)

These apply to the entire Flash memory (application + bootloader).

Common Lock Bit Modes

LB2 LB1 Protection Level Description
1 1 No Protection Full access for reading/writing
1 0 Program Locked Program cannot be read, but can be written/erased
0 0 Fully Locked No reading or writing allowed

🧩 2. Bootloader Lock Bits (BLB01, BLB02, BLB11, BLB12)

These allow you to control read/write permissions between the application code and the bootloader.

They determine:

  • Whether the bootloader can read/write the application section
  • Whether the application can read/write the bootloader section

Bootloader lock bits give fine-grained control for secure OTA updates, serial bootloaders, or mass-production programming.

📌 When Should You Use Lock Bits?

Use lock bits when you need:

  • Firmware security against reverse engineering
  • Protection from accidental overwrites
  • A secure bootloader that cannot be modified by user code
  • Safe in-field firmware updates

They are especially important in commercial or industrial products.

✔ Important Notes About Lock Bits
  • Lock bits can only be cleared by a Chip Erase, which also erases Flash memory.
  • EEPROM can be preserved during Chip Erase if EESAVE is enabled.
  • Always test lock bit settings carefully before deploying them in final hardware.

0 comments:

Post a Comment