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
- Atmel AVR STK-500 Development Board
- An ATMEGA or ATTiny chip
- AVR Studio 4 Software
- Arduino 0022 Software
- Arduino Bootloader HEX File
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 18.104.22.168 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:
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
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.