Skip to content

Burning the Fuses

jbaumann edited this page Oct 19, 2020 · 14 revisions

Calculating Fuse Values

To calculate the exact values for the different fuses (low fuse, high fuse and extended fuse) we could study the documentation and calculate the bits that way (I originally did that). But we can also find a number of fuse calculators online, and the one on which I’ve come to rely on in the meantime is the Engbedded Fusecalculator.

Using this fuse calculator we start with the default values for the ATTiny85, turn off CKDIV8 (we need 8MHz, not the 1 MHz default factory setting), and choose 2,7V for the brownout-detection setting (BODLEVEL 101). The startup time should be set to 6/14CK (SUT 00) according to the datasheet table 6-7 on p.28, since the brown-out detection introduces its own delay on startup to start the bandgap reference (this is not really that important the longer startup time only occurs on Reset, so in theory you could stay with SUT 10).

This leads to the fuse values 0xC2, 0xDD and 0xFF for low, high and extended fuse shown in the lower part of the web page (v2.8.4 and earlier need 0xE2, 0xDD and 0xFF).

Burn Fuses with ArduinoIDE and the ATTinyCore

With the ATTinyCore implementation by Spence Konde burning the fuses is extremely simple. Choose the correct entries in the menu (Board "ATTiny 25/45/85", Chip "ATTiny 85", Clock "8Mhz Internal", BOD Level "2.7V") and then use the menu item "Burn Bootloader" to set the fuses. These will not have the exact values given above (the startup time is left untouched, which leads to 0xE2, 0xD5 and 0xFF) but they are good enough.

Burn Fuses with AVRDude

To burn the fuses you use the program avrdude that is part of the ArduinoIDE. Sadly, it is a bit hidden and its location changes from time to time. The best way to identify the program path and the path to the configuration file for it is to simply copy & paste it from the output window of the ArduinoIDE after you have flashed the firmware to the ATTiny.

The avrdude command, general part

On my Macbook, with the ArduinoIDE 1.8.12, avrdude can be found under Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude

and the configuration file under

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf

We are using the following general parameters

-v -pattiny85 -cusbasp -Pusb -B3

-v for verbose, -pattiny85 for the processor, -cusbasp for the programmer, -Pusb for the interface used and -B3 for the speed with which the communication with the chip takes place.

Now avrdude knows how to communicate with our chip and which chip to expect.

The avrdude command, programming the fuses

The Fusecalculator linked above gives not only the correct fuse values but the parameters for avrdude as well, and we only have to copy them: -U lfuse:w:0xc2:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m

We simply add these after the general part of the avrdude command and can now program the fuses on the command line with the following command:

Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude            \
-C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf    \
-v -pattiny85 -cusbasp -Pusb -B3                                                 \
-U lfuse:w:0xc2:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m

Remember, you probably have to change the paths to executable and configuration file.

In principle writing the fuses should not interfere with the firmware you have already flashed, but time and again I had some problems with it and so I simply always flash the firmware again whenever I have changed the fuses.

Burn Fuses with the ArduinoIDE and the old ATTiny Board Definition

The ArduinoIDE can burn fuses as well, but only those that are hidden beneath menu items. If, for instance, you choose "Tools->Clock: Internal 1MHz" or "Tools->Clock: External 20MHz", this in fact leads to the ArduinoIDE using preconfigured entries for the fuses that are then burned whenever you choose the menu item "Tools->Burn Bootloader".

When you installed the board definitions for the ATTiny, these entries were installed as well as part of the package. By editing the file boards.txt you can change these entries and add you own.

Finding the Configuration File

First of all you need to find the location of your Arduino config files. Open the Preferences page and look for the location of the Preferences file preferences.txt. This is the base directory under which all board definitions etc. are stored. The ATTiny board definitions that we installed earlier can be found under packages/attiny/hardware/avr/1.0.2/. Here the file boards.txt can be found; it contains all the board and menu definitions.

Adding our own Fuse Set

If you examine the structure of the menu definitions, you can see that it is very logical and straightforward. We are adding the following menu item definition (I put it directly below the internal8 definition):

ATtinyX5.menu.clock.internal8bod=Internal 8 MHz BOD 2.7V
ATtinyX5.menu.clock.internal8bod.bootloader.low_fuses=0xc2
ATtinyX5.menu.clock.internal8bod.bootloader.high_fuses=0xdd
ATtinyX5.menu.clock.internal8bod.bootloader.extended_fuses=0xff
ATtinyX5.menu.clock.internal8bod.build.f_cpu=8000000L

If you look at the definitions for the fuses you see that the values are the exact values we calculated above. The last line defines the clock frequency assumed at compilation time for routines like delay(), millis() or micros() among others. It is very important to have this definition and have the correct value for it.

Save the file and restart your ArduinoIDE.

Burning the Fuses

You should now see a new menu item "Tools->Internal 8 MHz BOD 2.7V". Select it, choose "Tools->Burn Bootloader" and watch the ArduinoIDE burn the correct fuses.

Clone this wiki locally