8-bit AVR® Microcontrollers Fuses
AVR® microcontroller (MCU) fuses are the locations in non-volatile memory that define the hardware configuration of an AVR device.
Fuses are placed in a select section of memory and consist of a few registers. Each bit of the register represents a different fuse setting. Detailed information on which fuses are available in the different programming modes and their functions can be found in the device datasheet. Instruction clock speed, watchdog timer, and debug mode are just a few of the fuse settings available on most devices.
Fuses are changed at programming time with a connected programmer and MPLAB X IDE. They are latched in place after programming and also at the power-up of the device.
Unless careful consideration is given to which Fuse bits are programmed, it is easy for the novice programmer to brick their device (i.e., render the MCU un-programmable/un-debuggable in his/her application circuit).
AVR Fuses Summary
The device has three Fuse bytes. The following tables describe briefly the functionality of all the fuses and how they are mapped into the Fuse bytes. Note that the fuses are read as logical zero, “0”, if they are programmed.
Extended Fuse Byte for ATmega328PB
Extended Fuse Byte | Bit No. | Description | Default Value |
---|---|---|---|
- | 7 | - | 1 |
- | 6 | - | 1 |
- | 5 | - | 1 |
- | 4 | - | 1 |
CFD | 3 | Disable Clock Failure Detection | 0 (programmed, CFD disable) |
BODLEVEL2(1) | 2 | Brown-out Detector trigger level | 1 (unprogrammed) |
BODLEVEL1(1) | 1 | Brown-out Detector trigger level | 1 (unprogrammed) |
BODLEVEL0(1) | 0 | Brown-out Detector trigger level | 1 (unprogrammed) |
Note:
1. Please refer to Table BODLEVEL Fuse Coding in System and Reset Characteristics for BODLEVEL Fuse decoding in the device datasheet.
Fuse High Byte for ATmega328PB
High Fuse Byte | Bit No. | Description | Default Value |
---|---|---|---|
RSTDISBL(1) | 7 | External Reset Disable | 1 (unprogrammed) |
DWEN | 6 | debugWIRE Enable | 1 (unprogrammed) |
SPIEN(2) | 5 | Enable Serial Program and Data Downloading | 0 (programmed, SPI programming enabled) |
WDTON(3) | 4 | Watchdog Timer Always On | 1 (unprogrammed) |
EESAVE | 3 | EEPROM memory is preserved through the Chip Erase | 1 (unprogrammed), EEPROM not reserved |
BODLEVEL2(4) | 2 | Brown-out Detector trigger level | 1 (unprogrammed) |
BODLEVEL1(4) | 1 | Brown-out Detector trigger level | 1 (unprogrammed) |
BODLEVEL0(4) | 0 | Brown-out Detector trigger level | 1 (unprogrammed) |
Note:
1. Please refer to Alternate Functions of Port C in I/O-Ports chapter for description of RSTDISBL Fuse.
2. The SPIEN Fuse is not accessible in serial programming mode.
3. Please refer to WDTCSR – Watchdog Timer Control Register for details.
4. Please refer to Table. BODLEVEL Fuse Coding in System and Reset Characteristics for BODLEVEL Fuse decoding.
Fuse Low Byte for ATmega328PB
High Fuse Byte | Bit No. | Description | Default Value |
---|---|---|---|
CKDIV8(4) | 7 | Divide clock by 8 | 0 (programmed) |
CKOUT(3) | 6 | Clock output | 1 (unprogrammed) |
SUT1 | 5 | Select start-up time | 1 (unprogrammed)(1) |
SUT0 | 4 | Select start-up time | 0 (programmed)(1) |
CKSEL3 | 3 | Select Clock source | 0 (programmed)(2) |
CKSEL2 | 2 | Select Clock source | 0 (programmed)(2) |
CKSEL1 | 1 | Select Clock source | 1 (unprogrammed)(2) |
CKSEL0 | 0 | Select Clock source | 0 (programmed)(2) |
Note:
1. The default value of SUT[1:0] results in maximum start-up time for the default clock source. See the Fuse Low Byte for ATmega328PB table. Start-up times for the internal calibrated RC Oscillator clock selection in Calibrated Internal RC Oscillator of System Clock and Clock Options chapter for details.
2. The default setting of CKSEL[3:0] results in internal RC Oscillator @ 8MHz. See the Fuse Low Byte for ATmega328PB table. Internal Calibrated RC Oscillator Operating Modes in Calibrated Internal RC Oscillator of the System Clock and Clock Options chapter for details.
3. The CKOUT Fuse allows the system clock to be output on PORTB0. Please refer to Clock Output Buffer section in the System Clock and Clock Options chapter for details.
4. Please refer to System Clock Prescaler section in the System Clock and Clock Options chapter for details.
AVR Fuse Programming in MPLAB® X
Exit Debug Mode
The fuses cannot be programmed while debugging a project. The debug tool also needs to be disconnected. Select Debug > Disconnect from Debug Tool as shown.
Switch communication from debugWIRE to ISP
Right-click on the Project Name in the file explorer window and select Properties and then select OK at the bottom.
If a dialog appears asking if you would like to switch to ISP, select YES.
Switch to ISP
In the next dialog, select the pull down next to Interface and select ISP if not already selected.
Select mEDBG and Communication
In the next dialog box, select mEDBG and then scroll to Communication in the Option Categories pull-down menu, and then select OK.
Disconnect and Reconnect the Device
The power needs to be cycled on the device to restart this communication in ISP mode. Briefly unplug the device from your PC and reconnect. You will now be able to read the current status of the configuration fuses.
Read the Fuses
Select Window > Target Memory Views > Configuration Bits. A new window will appear showing the status of each of the fuses. They will appear RED until the device is read. Now select the Read Device Icon in the upper left of the new window. If successful, the readings will turn to black text.
Making a Change to the Fuses
Currently, the fuses are configured to turn off the Watch Dog Timer. We know this because in the WDTON row, the setting indicates CLEAR. We will turn it in on in the following example by changing it to SET.
The WDTON option is set by the High Fuse setting of bit 4. The High Fuse currently has a hex value of 0xDF. If we change bit 4 to a 0, the hex value becomes 0xCF.
Create a new project or add the following code toward the top of an existing project (just below the #include statements)...
FUSES = {
.low = 0xE0, // LOW {SUT_CKSEL=EXTCLK_6CK_14CK_65MS, CKOUT=CLEAR, CKDIV8=CLEAR}
.high = 0xCF, // HIGH {BOOTRST=CLEAR, BOOTSZ=256W_3F00, EESAVE=CLEAR, WDTON=SET, SPIEN=SET, DWEN=CLEAR, RSTDISBL=CLEAR}
.extended = 0xFE, // EXTENDED {BODLEVEL=1V8, CFD=CFD_ENABLED}
};
Press the Make and Program device button and your new Configuration bits should reflect that the WDTON is now set.
Other fuses can be assigned SET or CLEAR in the same manner.
AVR Fuse Programming in Atmel Studio
The Device Programming window (also known as the programming dialog), gives you the most low-level control over the debugging and programming tools. With it, you can program the device's different memories, fuses and lock bits, erase memories, and write user signatures. It can also adjust some of the starter kit properties, such as voltage and clock generators.
The programming dialog is accessible from the Device Programming icon on the standard toolbar or in the Tools > Device Programming drop-down menu selection.
Device Programming Icon
Menu Selection
The Device Programming window will appear with various programming options listed on the left.
Select the Fuses option
The Fuses pane will appear showing the fuses of the selected device. Fuse settings are presented as checkboxes or as drop-down lists. The Fuse Register settings also appear in the lower pane as hexadecimal values.
Read
Press the Read button, in the lower right corner, to read the current value of the fuses. If the Auto read box is checked, the fuse settings will be read from the device each time you enter the fuse page.
Change
The fuse settings can be changed via the dropdown boxes. Some selections require a box to be checked or unchecked.
Program
After any changes are made to the settings, press the Program button to write the current fuse setting to the device. If the Verify after programming box is checked, the settings will be verified after a programming operation is completed.
Latch
The fuse values are latched when the device enters programming mode, and changes in the fuse values will have no effect until the part leaves the Programming mode. This does not apply to the EESAVE Fuse, which will take effect once it is programmed. The fuses are also latched on Power-Up in Normal mode.
Adding Fuse Settings to .elf Production File
The fuse API allows a user to specify the fuse settings for the specific AVR device for which they are compiling. These fuse settings will be placed in a special section in the ELF output file after linking.
Programming tools can take advantage of the fuse information embedded in the ELF file, by extracting this information and determining if the fuses need to be programmed before programming the Flash and EEPROM memories. This also allows a single ELF file to contain all the information needed to program an AVR MCU.
Converting Studio .elf format to .hex for Programming with MPLAB® X Tools
If you look at the build output in Studio IDE, you’ll see how the .hex file is made from the .elf file, e.g.:
"E:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "ATtiny416.elf" "ATtiny416.hex"
This means: make the .hex but discard .eeprom, .fuse, .lock, .signature, and .user_signature files.
If you want a HEX file with those sections left over for use with MPLAB X IDE programming tools, make a post-build step, e.g.:
"$(ToolchainDir)\avr-objcopy.exe" -O ihex -R .eeprom -R .lock -R .signature -R user_signatures "$(OutputDirectory)\$(OutDir)\$(OutputFileName)$(OutputFileExtension)" "$(OutputDirectory)\$(OutputFileName).with-fuse.hex"
Bricking a Device
The following fuse bytes (and default fuse bit settings) are shown for the ATmega328PB. Key fuse bit settings which could brick the device are highlighted:
FUSE LOW Byte
- CKSELn [n=3:0] – Selects clock source for the system clock.
- SUTn [n=1:0] - Selects the delay period from when the External Reset is released (not active anymore) until the Internal Reset is released.
- CKOUT – Enables clock output on PB0.
- CKDIV8 – Configures the CPU clock to be pre-scaled by 8.
FUSE HIGH Byte
- BOOTRST - If you use a bootloader to flash MCU, this bit must be enabled.
- BOOTSZn [n=1:0] - These bits select the bootloader section size.
- EESAVE – Exclude the EEPROM during a chip erase procedure.
- WDTON – Enable Watchdog Timer by HW.
- SPIEN – Enable/Disable In-Circuit Serial Programming (ISP) mode.
- DWEN – Enable/Disable DebugWire debug interface.
- RSTDISBL – Enable/Disable nRESET pin usage as IO.
FUSE EXTENDED Byte
- BODLEVELn [n=2:0] - They select the brown-out voltage level when the VDD supply is no longer suitable for operation and the MCU is reset.