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. You want version 4.19
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
#!/bin/sh # # Using ESX you can virtually connect the AVR Programer into the VM # This command will drive the AVR ISP and flash a chip # YELLOW WIRE is PIN 1 # Power to AVR UNIT # Power to Arduino avrdude -v -c avrisp2 -p m328p -P /dev/ttyUSB0 -b 115200 \ -U efuse:w:0x05:m \ -U hfuse:w:0xde:m \ -U lfuse:w:0xff:m \ -U flash:w:jeenode-rf12demo-bootloader.hex