Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

Burning the Bootloader on an ATMega8 or ATmega168

By Digger450 and djmatic (STK-500 additions by Hockeyrink)

This tutorial shows you how to use AVR Studio 4 (free) and an AVR-ISP mkII programmer to burn the Arduino bootloader onto an ATmega8 or ATmega168.

Here's what you'll need:

  • An Arduino in need of a bootloader
  • A copy of the the ATmega8 or ATmega168 or ATmega328 bootloader hex file. The latest bootloaders can be found on your harddrive at <arduino-install-directory> \Arduino\hardware\arduino\bootloaders\atmega\
  • A PC running Windows, or a MAC running Parallels build 3150 or later.
  • AVR Studio 4
  • An AVR-ISP mkII programmer.

Alternately, the Arduino IDE can now burn the bootloader for you, but you will still need a hardware programmer.

1. Install AVRStudio 4 on a PC running windows XP.

Alternatively, on an Intel-based Mac, you can use Parallels Build 3150 or later with Windows XP.

2. Connect the AVRISP mkII programmer to a USB port.

Note: If you're using an STK-500, see the end!

3. Start AVR studio and 'connect' the programmer in the software. Select the appropriate programmer and port.

4. Connect the AVRISP mkII to the ISP header on the BT module. The side of the ribbon cable with the red stripe indicates pin 1. The light on the programmer will change from red (error) to green (happy). The software will tell you if the cable is in the wrong position.

5. On the "Program" panel of the software, select the device as Amega168 or Atmega8 depending on which chip you have.

6. On the "Program" panel of the software, select "input hex file" in the flash section. Choose the appropriate hex bootloader file for your chip (they are different).

7. From here on in, when you click on one of the panels in AVRPROG, the software will read the values on the chip into the values in the software. So, when you click the 'fuses panel', it will set up that panel to match whatever the fuses are on whatever you're about to program.

8. Click the "Board" panel, set and write the ISP frequency. If this is a virgin chip you must select 125.0 kHz. If you have already flashed this chip you can set it to 2.0 Mhz without issues. It will be a long day of programming if you don't take this step, as burning at 1.049 Khz takes forever.

9. Click the "Fuses" panel of the software. It will read the existing fuses from the chip to be programmed.

Here are the detailed settings for the fuses:

ATmega8 Fuse Settings

Once set the fuses should read 0xCA and 0xFF, which is equivalent to:

  • Boot Flash section size = 512 words Boot start address = $0E00; [BOOTSZ=01]
  • Boot Reset Vector Enabled (default address = $0000); [BOOTRST=0]
  • CKOPT fuse (operation dependant of CKSEL fuses); [CKOPT=0]
  • Brown-out detection level at VCC=2.7V; [BODLEVEL=1]
  • Ext. Crystal/Resonator High Freq.; Start-up time: 16K CK + 64ms; [CKSEL=1111 SUT=01]

ATmega168 Fuse Settings

Once set the fuses should read 0xF8, 0xDF and 0xFF, which is equivalent to:

  • Boot Flash section size = 1024 words Boot start address = $1C00; [BOOTSZ=00]; default value
  • Boot Reset Vector Enabled (default address = $0000); [BOOTRST=0]
  • Brown-out detection disabled; [BODLEVEL=111]
  • Ext. Crystal Osc.; Frequency 8.0 - MHz; Startup time PWRDWN/RESET: 16K CK/14 CK + 64ms; [CKSEL=1111 SUT=0]

10. Click the "LockBits" panel of the software.

ATmega8 and ATmega168 LockBit Settings

Once set the lockbits should read 0xFF for ATmega8 and 0xCF for ATmega168, which is equivalent to:

  • Mode1: No memory lock features enabled
  • Application Protection Mode1: No lock on SPM and LPM in Application Section
  • Boot Loader Protection Mode3: LPM and SPM prohibited in Boot Loader Section

11. With the above settings entered, AVR PROG can automatically burn chips. On the Auto panel, select the following:

  • Erase Device

  • Program FLASH
  • Verify FLASH

  • Program Fuses
  • Verify Fuses

  • Program lock bits
  • Verify lock bits

Hit "Start" to program. It should be automatic from there. To program another, just connect it to the programmer, and hit 'Auto.'

When you reopen the program the next time, it should remember many of these values. Note that every time you click the fuse or lock bits panel, the software will read in whatever settings the current device is programmed with. This can lead to problems, so be sure to double check that the settings you want to program are correct before you hit the program button.

Programming the Arduino firmware to a ATmega168 with the STK-500 in High-voltage mode

This addition is to help those, who like me, had some issues with the lack of documentation on exactly how to set up an STK-500 to burn the firmware. Here we go:

1) PINS Start by making sure you have jumper shunts across the first 4 pins: VTARGET AREF RESET XTAL1

With the last pin (OSCSEL), make sure the jumper on the two RIGHTMOST pins

The next two sets of pins are the troublesome ones.

From the STK-500 programming documentation, you need to run a jumper from the RIGHTMOST pin of BSEL2 to the pin "PC2" in the "PORTC" block near the left side of the board (assuming the RS232 jacks are to your right side). Use one of the spare STK-500 jumper cables to make this connection.

"PJUMP" needs jumpers running LEFT/RIGHT on the top and bottom sets of pins. I made the mistake of using another jumper cable, and accidentally made my connections up/down, not left/right. GARRH! BTW, when I say "left/right", this is with the STK-500 sitting so you can read "PJUMP" normally under the 4 pins.

2) CABLES Like normal, run a 10-pin ribbon cable from "PROG CTRL" to "PORTD", and "PROG DATA" to "PORTB". You do not need the 6-pin ISP cable installed for High-V programming.

3) PROGRAMMING I cribbed a batch file from Seandockray who had borrowed the settings from Bruno Nadeau. Copy and paste this into a batchfile (I used "firmware.bat", and run it:

Start copy below this line


: We're assuming a few things:
:   1) Your firmware is at C:\arduino-0009\bootloader168, and it is the ATmegaBOOT_168_diecimila.hex
:   2) Your STK software is at C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe
:   3) You're trying to program a ATmega168 using the high-voltage mode of the STK-500
:If they're not, make the edits below!


:Change to firmware directory
cd C:\arduino-0009\bootloader168

: Set fuse bits, lock bits, voltages
"C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" -dATmega168 -ut5.2  -e -ua5.0 -!3686400 -lFF -LFF  -fDFFF -EF8 -mp -q


: Burn Arduino hex bootloader file
"C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" -dATmega168 -pf -vf -ifATmegaBOOT_168_diecimila.hex -mp -q

: Lock it down
"C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" -dATmega168 -lCF -LCF -mp -q

@echo CHECK FOR PROBLEMS ABOVE before closing this window!
pause


End copy above this line

If you want, sneak back to the above page, and do all the settings via AVR Studio. Just make sure you're using the "High Voltage" mode!