Burning the Arduino Bootloader with an AVR STK500 Development Board

I recently discovered that we had an old AVR STK500 development board lying around at work and when I had some free time I decided to play with it and see if I could use it to burn the Arduino Bootloader onto some old ATmega168 chips we had lying around. I was somewhat overwhelmed by this board as it had so many jumpers and connectors on it that I didn’t have a clue where to begin, on top of that there was no manual to be found or even a model number on it to look up — the only identifier it had on the board was the Atmel AVR logo. I was only able to find a model number for it after digging through pages of images that came up on a Google search, once I found a picture of the same board I found my way back to this page which gave me the information I needed. From there I was able to dig up the manual as well as a few extremely outdated guides on setting it up to program an ATmega chip with a bootloader. After much frustration I finally managed to get the code to flash.

You Will Need

Configuring the STK-500

This is the trickiest part of the setup, if you have the manual you’ll be following the directions for the ATmega8 device. The configuration is exactly the same for the ATmega168 as well as the ATmega328. To make sure there is no confusion, if I say to the right I’m referring to the side with the power and two RS232 ports, and the left would be the opposite side where you’ll see a row of push buttons. Though this should go without saying, make sure you have the power disconnected from the board and you are properly grounded so that you do not cause any E.S.D. damage to your board or components.

First you’ll be setting some jumpers. Place a jumper across the pins for VTARGET, AREF, RESET and XTAL1. Next you’ll place a jumper over the two right-most pins of OSCSEL. You’ll also be installing two jumpers on the PJUMP pins, be sure to connect the top two pins with one jumper and the bottom two with another, so the jumpers will be running left to right. The next jumper will be one of the trickier ones, you will need a longer jumper wire and you will be running it from the right most pin of BSEL2 to the pin labeled PC2 which is located in the bank of pins labeled PORTC which is to the bottom left side of the development board.

Next you’ll be running two ribbon cables across the board (as seen in section 3.7.2.1 of the manual). You’ll be connecting the PROG DATA header to the PORTB header as well as connecting the PROG CTRL header to the PORTD header. I’ve included figure 3-17 from the manual to demonstrate this:

Arduino STK500

Finish up by placing the chip into the socket labeled SCKT3200A2 which is the one outlined in Green. Pay attention to the small notch on the left edge of the socket, this will match up with a notch on one end of the chip.

Burning the Bootloader

Quick Sheet:

  • Tools
  • Program AVR
  • Connect…
  • Platform: STK500
  • Port: COM1
  • Connect…
  • Tab: Main
  • Device: ATMega168 (or as desired)
  • Programming Mode and Target Settings: PP/HVSP mode
  • Tab: Program
  • Select the HEX file for your chip
  • Click Program
  • Tab: Fuses
  • Extended: 0xF8
  • High: 0xDF
  • Low: 0xFF
  • Program
  • Tab: LockBits
  • Lockbit: 0xFF
  • Program

Unlike when using an ISP programmer through the Arduino software there are a few more things to do than just click “Burn Bootloader.” For just the cliff notes follow the list on the right, or to jump to the video, otherwise keep reading. If you’ve just opened the software for the first time and it’s asking you to start a new project or open one, you’ll actually want to hit cancel. Now in your IDE select the Tools menu and then Program AVR and then select Connect… Now you’ll be presented with a screen asking about the LockBits, click back to the Main tab and select your Device and set the programming mode to HVSP. Before leaving this tab I recommend hitting Read Signature to to see if it reads the device fine, if it’s not hooked up right it will likely fail at this point.

Move on to the Program tab and then load your hex file. You’re going to need the right hex file for the chip and board you’re going to be working with. So go into your Arduino folder (e.g. C:\Program Files\Arduino\) under the Hardware\arduino\bootloaders\ and start looking for one that makes the most sense. If you don’t have the Arduino software installed yet or on this computer then another good source is LeafLabs on Google Code. To be honest I’m not sure what the difference is between all the bootloaders, I just use the one in the atmega8 folder and have had no issues. It’s also only 3kb verses 30kb which is the one whose name best maches the ATMega168 chips I’m using in this example. Once you’ve loaded the file into the AVR Studio under the Flash heading you can go ahead and hit program. I always have the options to erase the chip and verify afterwards, so if you don’t you may want to do that manually. If there are no errors in the bottom text move on to the Fuses tab.

Under the Fuses tab you will have to set some hex values. For the ATMega18 I was using in this example I had to set Extended to 0xF8 then High to 0xDF and Low to 0xFF. This may vary depending on the chip so make sure to look it up before hand. Before moving on click Program and check the log for errors.

Finally, check the LockBits page. These seem to reset to 0xFF after every program action so set them to 0xCF and hit Program.

At this point your bootloader should be burnt onto your ATMega chip and you should now be able to use it in your Arduino board. So pop it out of the STK500 and back into your Arduino board and fire up the software. From the examples menu select Blink and upload it to your device. If the LED alternates between on and off endlessly then you are ready to rock.


Tags: , , , , , , ,

  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

8 Responses to “Burning the Arduino Bootloader with an AVR STK500 Development Board”

  1. John says:

    Hi,
    Thanks for your example above… I do need some additional help if possible…

    I’ve tried your above example with my STK500 V2 with no luck. I am using the 328P chip and programming it for the Arduino UNO. I wire the STK500 V2 as stated above and plug in a brand new Amtel 328P in the Green Socket, then setup everything in AVR Studio. I do setup AVR Studio for the Amtel 328P instead of your 168 above. I then read the 328P signature successfully. I then write the ‘ATmegaBOOT_168_atmega328.hex’ file and verify. No problems!! When I try and write the Fuses and Lockbits I do get verify error msgs. I’ve looked everywhere for the values to plug in here, but everyone has a different opinion on what to enter. I’ve tried the fuse calculator and am at wits end here… Could you please guide me in the process of programming the Fuses and Lockbits? I would greatly appreciate it!
    Sincerlely,
    John

  2. John says:

    Hi Again,
    Well, after a number of failures… I tried something new and completely different! I read the ‘.hex’ file from a store bought programmed chip using AVR Studio and then burned the resulting .hex file to a blank chip. Voila… Works like a charm! With the bootloader now installed I can now program my Arduino 328 chip using the Arduino program. I’ve only tried it with the ‘blink’ program but I’m now getting the RX – TX Lights flashing while programming so I’m sure it’s working fine…

    In addition to programming the 328P chip with my own .hex file I burned the following Fuse and Lockbits below:

    Fuses: Extended 0xFD
    High 0xD6
    Low 0xFF

    Lockbits: 0xCF

    Thanks for making me think 🙂 …
    John

  3. EightBits says:

    Looks good. I have a STK-500 and recently received my first UNO and it works great on my Ubuntu PC.
    I do use Atmel Stdio and STK-500 on the XP-pro pc and have programmed various AVR devices.
    I thought John’s experience seems to verify what I thought would work – thanks John for your posting and your work.

    Also, if I understand correctly, AVRDUDE can also program using Ubuntu via STK-500 or a Dragon?
    Did you set the fuses(s) after the initial hex burn or is it required prior to programming the hex file ?
    I also was thinking that the Studio you can read the fuses and then use that ?

    Once again, a million thanks to the poster’s on this subject!

  4. Rahul says:

    Hi Jhon
    Thanks to you for sharing fuse information. I have pololu stk500 v2 avr programmer. I got one problem that I am not able to re programme my atmega328. It will be very helpfull if you share any tricks to solve this issue.

  5. FettesPS says:

    @Rahul – Thanks, but who’s Jhon?

  6. Rahul says:

    I am very sory. The name should be John. Now I am able to re programme my Atmega328. Thanks once again for sharing the document.

  7. Asimo says:

    Done this with atmel studio 7. Bootloader loaded sucessfully on atmega328p-pu. The socket next to the green one gave me some error while programming the fuses though.
    Thanks a lot.

  8. Asimo says:

    PS: in the quick sheet, the lockbit is: 0xCF not 0xFF in case you didn’t read the final part.

Leave a Reply