Lesson 1
This lesson will take you through the steps of preparing the Atmel STK500 Starter Kit and then downloading a previously compiled firmware into a new ATmega168.
Preparing the STK500 board
The STK500 comes with a sample micro-controller, a 40 pin ATmega16 that is in the (red) socket that is labelled SCKT3000D3. The sample ATmega16 is pre-programmed with a LED/switch demo program that is documented in Section 9 of the STK500 User Guide.
Remove this chip since we will be using the ATmega168 instead.
Make sure that the STK500 is powered off when you insert or remove a chip. Always store any unused AVR chips in anti-static foam or container.
Locate the ATmega168 socket and installing the chip
Fetch your spare ATmega168. To be brief, I will henceforth call it the mega168. Insert the chip into the 28 pin (0.3" centers) DIP socket that is labelled SCKT3200A2. Make sure none of the pins sticks outside the socket. It is often useful to bend the pins so that they do not spread as much, before inserting a new chip.
Notice that the silkscreen around this socket is green in color. The areas around each of the programming sockets are painted white, red, green or blue. There are two 28 pin DIP sockets. One has a white slikscreen and the other has a green silkscreen. The mega168 goes into the green socket.
Make sure pin 1 of the mega169 is properly oriented. There is a small circular indentation on the plastic package next to pin 1 of the mega168 chip. There should also be a notch at the corresponding short end of the chip package. Note that the green silkscreen around the SCKT3200A2 is not perfectly rectangular; the green rectangle has a missing corner. Pin 1 of the mega168 should go into that corner of the DIP socket (seen below at the bottom right of the socket).
Jumpers
Fetch a 6 pin jumper cable from the STK500 kit. The kit
should come with a bag of 2-, 6- and 10-wire flat ribbon
jumpers with IDC connectors at their ends. Insert one of
the IDC plugs into the the header that is named ISP6PIN and
jumper it to the header named SPROG2 that is located two
headers away from the ISP header.
Notice that the silkscreen around SPROG2 is painted green.
Everything is color coded on the STK500 board. Green ISP
connection... green AVR chip.
What you have just done is to wire the ISP programming
signals to the ISP pins on the mega168.
Now locate a row of 10 pin IDC headers on the STK500 board
that are named PORT A, PORT D, PORT E/AUX, PORT B and PORT
C.
You should also find another 10 pin IDC header named LEDS
near to the header that is labeled PORT B.
Fetch a 10 pin jumper cable from the STK500 kit and connect
PORT B to LEDS. Be sure to connect Pin 1 of one header to
Pin 1 of the second header. Labels for pins 1 and 2 of the
headers are silkscreened on to the circuit board.
What you have done is to wire the Port B pins of the
mega168 to a row of eight light emitting diodes (LED).
These eight LEDs are next to the eight push buttons which
are located near one edge of the STK500 board.
You are now finished with the AVR jumpers that will be used
for Lesson 1.
(For future reference, note that there is also a 10 pin IDC
header that is connected to the push buttons, and a a 2-pin
header named RS232 SPARE, which connects an AVR to the
spare RS-232 connector through RS-232 drivers.)
Power and Serial Port
Locate a small (very small!) slider switch that is
near one corner of the STK500 board and labeled POWER.
There is a coaxial power jack that is next to this switch.
Connect a 12 volt power source to the coaxial power jack,
but do not turn power on with the slider switch yet.
Any supply between 10 and 15 volts, and capable of 500 mA
of current will work. Note that the center pin should carry
the positive end of the supply. A power cable with the
appropriate jack (2.5mm center pin) is provided in the
STK500 kit.
Connect the 9 pin male DE-9 (often misnamed DB-9) of a USB
serial port adapter to the female DE-9 connector that is
labeled RS232 CTRL. A second DE-9 connector is named RS232
SPARE. Leave the spare connector alone for now. You can in
the future use that DE-9 connector to communicate with the
USART on the AVR chips.
You are now done with STK500 preparations.
Setting up the Software Tools
Follow the Resources page to install the AVR tool chain on your Macintosh. Also install AVR Tools from here.
To confirm that avrdude (the firmware downloader from the tool chain) is properly installed, launch Terminal.app now. Terminal is in the /Applications/Utilities folder. Type "avrdude" (without the quotes) to the Unix shell prompt. Scroll back to the beginning of the Terminal window and if you should see something like the following. If so, avrdude is properly installed and AVR Tools should be able to use it.
If you receive a response that looks like "avrdude: Command not found," the installation was not successful. Check the installation steps.
You can now quit Terminal.app.
Checking the Serial Port
If you do not know the name of your serial port, now is a good time to find what it is; AVR Tools has some tools that you might find useful.
Launch AVR Tools and select Show Serial Ports in the Window Menu of AVR Tools. AVR Tools should open a window named Serial Ports, with a list of serial ports that it has found.
Remove the USB connector of the serial port adapter from the computer (not the DE-9 connector, but where the USB connector attaches to the Macintosh). You should see a Removed: message as shown below.
This identifies the name of the port (the one shown above is for the KeySpan USB High Speed Serial Adapter). If you do not see a "removed" message when you unplug the device, check to make sure that the driver for your serial adapter is properly installed.
If all is well, plug the serial port device back in (you should also see an "Added" message), and close the Serial Ports window.
Setting up the Example Firmware
Download the FirstLight Download disk image. Expand the disk image and drag copy the folder in the volume to your hard drive.
The folder contains two files, firstlight.avr is an AVR Tools saved session file, and firmware.hex is a firmware file for the mega168.
When you double click on the firstlight.avr file, an empty session should open in AVR Tools. You can also open this file from the File menu in AVR Tools instead of double clicking on it.
Select the Program tab in the session window. Use the browse button to the right of the text field named Flash to select the firmware.hex file in the same folder as firstlight.avr. Next, select the Device tab and select ATMEGA168 as the AVR device. Proceed to the Programmer tab, and select "Atmel STK500 Version 2" if it is not already selected. Finally, select the Port tab and select the serial Port that you are using to download the firmware to the STK500.
Select Save in the File Menu to save your session settings.
Downloading Firmware
Power the STK500 development on (slider switch next to the coaxial power connector).The red power light next to the switch should light up. Now select the Program tab in AVR Tools window and click on the Download button at the bottom right of the window.
If everything is working, you should see the firmware being downloaded, and ending with a window that looks like this:
You can use the vertical scroller or change the size of the AVR Tools window to see more of the response (in red) from avrdude.
The STK500 should start the mega168 right after a successful download. If everything is working, the first LED should be flashing on and off every 1 second. You have just written a program into the AVR's flash memory.
If you turn the power in the AVR off and then on again, the LED should again begin blinking, showing that the program has been written into Flash memory.
Proceed to Lesson 2.