This is an old revision of the document!
ISP with an STK500 to program a ATMEGA328
This USB style STK500 AVRISP unit is quite popular.
However, it can be hard to work out exactly how to use it to program your AVR chips. These notes might help get you started.
The first thing to do is to download a copy of AVR Studio. This has a decent built-in programming capability and works well with the STK500 unit.
Depending on the board that you will use to host the AVR chip that is to be programmed, you might need an external power supply unit. We use this inexpensive serial Arduino board. To use it as a programmer, we require to plug in both the ISP connector and have external power applied to the little DC jack plug on the board. The important thing to note is that your board should have a six or ten pin ISP connector. Our board has a six pin connector.
This board can be purchased from the HAH shop.
Next, we plug everything together and do some basic configuration.
First off, find your AVR chip & plug in into the socket on the board. Be sure to insert it the correct way around.
The USB STK500 terminates in a ten pin IDC socket. Atmel used to use a ten pin header for ISP, but more recently swapped to using a six pin one. Our board has a six pin ISP header, so we need to use the little ten way to six way adaptor which is generally supplied with the STK500 programmer. It is important that this is connected the right way around … see the picture below (red stripe on the ribbon cable is near to the red wire on the adaptor).
The other end of this cable needs to be connected to the ISP header on the board. See below for the correct orientation (yellow wire on pin 1, red on pin 2).
We are now ready to plug the STK500 unit into our PC. This uses a standard A-B style USB cable which may well have been supplied with the STK500 unit. The STK500 unit appears to the PC as a standard COM port. It you open the device manager, you can see that it's based upon the popular Prolific device. Take a note of the COM port number that is assigned to the programmer.
The next step is to configure AVR Studio to find the STK500. Start up AVR studio and select the 'Tools/Program AVR/Connect' menu item. Select the STK500 option and the COM port that was assigned above. In our example, we were assigned COM 3. Press the 'Connect' button. At this stage, you should see a green LED illuminated on the STK500 unit.
It's now time to plug in the external power supply. We used a wallwart one, set for 9VDC.
Let's check that we are able to communicate with the board. Select the 'Fuses' tab … you should see a screen like the one below. Note that if you are programming for the HAH/Arduino, you want to uncheck the 'CKDIV8' checkbox (otherwise the xtal frequency will be divided by 8 … this fusebit is 'on' by default on a new 328 chip). Also choose the shown option on the SUT_CKSEL dropdown list.
Now, if you are intending to compile your own code within the Arduino environment, it's important that you select the correct target AVR board before compiling your sketch.
In particular, if you are compiling for the HAH PCB, you will need to modify your 'boards.txt' file Add this to the end of the 'boards.txt' file, on Windows, it's in C:\Program Files\arduino-0022\hardware\arduino
Then, select the 'HAH' board from the Arduino 'Tools/Board' menu, before you do a compile.
############################################################## hah.name=HAH hah.upload.protocol=stk500 hah.upload.maximum_size=32256 hah.upload.speed=115200 hah.bootloader.low_fuses=0xff hah.bootloader.high_fuses=0xde hah.bootloader.extended_fuses=0x05 hah.bootloader.path=optiboot hah.bootloader.file=optiboot_atmega328.hex hah.bootloader.unlock_bits=0x3F hah.bootloader.lock_bits=0x0F hah.build.mcu=atmega328p hah.build.f_cpu=7372800L hah.build.core=arduino
We are now ready to loadup the code to program our device. Move to the 'Program' tab and locate the .hex file which is created by your compiler. Note: if you are using the Arduino compiler, the .hex file is found in a temporary directory under the 'user' account e.g. on my machine
C:\Documents and Settings\User1\Local Settings\Temp\build47247231628265855.tmp\liveboxHAH.cpp.hex
Note that this file is truly 'temporary' in that it is deleted when you close the Arduino compiler UI.
Then press the 'Program' button, the LEDs in the STK500 unit will flash, your chip will be programmed and the load verified. Job done!
AVRDUDE with AVRISP on Linux
[root@wombat avrisp]# avrdude -v -c avrisp2 -p m328p -P /dev/ttyUSB0 -b 115200 -Uflash:w:jeenode-rf12demo-bootloader.hex avrdude: Version 5.10, compiled on Dec 19 2012 at 21:20:20 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch System wide configuration file is "/usr/local/etc/avrdude.conf" User configuration file is "/root/.avrduderc" User configuration file does not exist or is not a regular file, skipping Using Port : /dev/ttyUSB0 Using Programmer : avrisp2 Overriding Baud Rate : 115200 AVR Part : ATMEGA328P Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PC2 RESET disposition : dedicated RETRY pulse : SCK serial program mode : yes parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 ByteDelay : 0 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- eeprom 65 5 4 0 no 1024 4 0 3600 3600 0xff 0xff flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00 signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00 Programmer Type : STK500V2 Description : Atmel AVR ISP mkII Programmer Model: AVRISP Hardware Version: 15 Firmware Version Master : 2.10 Vtarget : 0.0 V SCK period : 204.0 us avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.02s avrdude: Device signature = 0x1e950f avrdude: safemode: lfuse reads as 62 avrdude: safemode: hfuse reads as D9 avrdude: safemode: efuse reads as 7 avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "jeenode-rf12demo-bootloader.hex" avrdude: input file jeenode-rf12demo-bootloader.hex auto detected as Intel Hex avrdude: writing flash (32670 bytes): Writing | ################################################## | 100% 4.20s avrdude: 32670 bytes of flash written avrdude: verifying flash memory against jeenode-rf12demo-bootloader.hex: avrdude: load data flash data from input file jeenode-rf12demo-bootloader.hex: avrdude: input file jeenode-rf12demo-bootloader.hex auto detected as Intel Hex avrdude: input file jeenode-rf12demo-bootloader.hex contains 32670 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 7.15s avrdude: verifying ... avrdude: 32670 bytes of flash verified avrdude: safemode: lfuse reads as 62 avrdude: safemode: hfuse reads as D9 avrdude: safemode: efuse reads as 7 avrdude: safemode: Fuses OK avrdude done. Thank you. [root@wombat avrisp]#