Randall converted an Arduino into AVR chip programming hardware for use with AVRDude. The project programs AVR tiny13 and other tiny AVR chips using an Arduino. He provides code and instructions to implement the Atmel AVR910 In System Programming protocol.
This article was submitted by Randall Bohn as part of the “Hobby parts for articles” program. Randall received the Arduino Bare Bones Board kit for this great project.
I ported the Atmel AVR910 In System Programmer protocol to the Arduino. Now I can write programs to my ATtiny2313 and tiny13 chips. The Arduino sketch is available for download here. It works with the AVRDude programming software. This article will show how to use the Arduino to upload a program to the tiny13. The first step is to download the zip, extract the .pde file, then load it into the Arduino IDE, and write it to the Arduino. Next we can hook up the tiny13 chip.
The original AVR910 programmer didn’t support the tiny13 chip. I added tiny13 support to the Arduino version and assigned it part ID 1. I had to modify the avrdude.conf file also. I just added the following line
to the tiny13 section right after the stk500_devcode line.
I put the tiny13 chip on a solderless breadboard, and connected power to it from the Arduino. I also put a bypass capacitor from lead 8 to lead 4 on the tiny13. This helps smooth out the power to the chip.
I added LED support when I ported the avr910. The LED turns on when the system is in Programming mode. Add the LED to the breadboard. Connect it to the ground line with a 1Kohm resistor and to the Arduino pin 9. Mind the polarity of the LED. The reset line should also be connected, from pin 10 on the Arduino to pin 1 on the tiny13.
Next connect the SPI interface. The Arduino’s Mega8 has hardware support for SPI. The SPI lines need to be connected to the tiny13 as follows:
|Pin 13 (SCK)||Pin 7|
|Pin 12 (MISO)||Pin 6|
|Pin 11 (MOSI)||Pin 5|
I use this cable to connect the SPI lines to the breadboard. The cable has to be twisted once to match up properly when the Arduino is next to the breadboard as in the photos above.
With everything connected you can power up the Arduino and start using AVRDUDE. First you need to know which port the Arduino is using. My USB Arduino shows up on port com4: so I’ll use that in the examples. We need to tell AVRDUDE which port to use, which part we are using, and which ISP programmer we are using. If you run following command line it should connect to the tiny13 and read the device signature (0x1e9007).
> avrdude -P com4 -p t13 -c avr910
AVRDUDE will also complain that it cannot read lfuse properly. Add the -u switch to get past this limitation.
> avrdude -P com4 -p t13 -c avr910 -u
With that working we can go into terminal mode with AVRDUDE and check the tiny13.
> avrdude -P com4 -p t13 -c avr910 -u -t
Enter ‘sig’ to view the device signature again:
Reading | ################################## | 100% 0.02s
Device signature = 0x1e9007
Enter ‘read flash 0 16’ to read the first 16 bytes of the flash memory. If the chip hasn’t been programmed it should be all 0xFF. You can also use hex numbers as follows: ‘read eeprom 0x10 0x10’.
With AVRDUDE in terminal mode we can write to the eeprom but not the flash on the tiny13. To store the string ‘BEEP’ into the eeprom you could enter the following:
avrdude> write eeprom 0 66 69 69 80 0
avrdude> read eeprom 0 8
If that worked you just wrote to the eeprom and read the contents back. Enter ‘quit’ when you are done with terminal mode.
AVRDUDE won’t write to the tiny13 flash in terminal mode because the flash is programmed in page mode. You have to write the flash from the command line. The -U switch is used to read and write memories from the command line. You can use more than one -U command at a time. Another thing to be aware of is that AVRDUDE will erase the chip before writing flash memory. Anything in EEPROM will have to be reloaded if you write to flash.
Start with the base command:
> avrdude -P com4 -p t13 -c avr910 -u
The add the -U command at the end. To write file ‘target.hex’ to the tiny13 use the following:
This is the simplified syntax. You can use it when you want to write a hex file to the chip flash. The full syntax to write is:
(write target.hex to flash, target.hex is Intel S-Record format.) AVRDUDE can figure out the format of the file, so you can actually leave the :i off.
To write the EEPROM use:
You can also read out the chip contents and verify against a file on your disk.
The basic development workflow I use is to build the software in AVRStudio 4, then use AVRDUDE to write to the target chip. I’ve used it to program the tiny13, tiny15, tiny2313, and the mega8.
Randall Bohn lives in Orem, Utah with his wife and three kids. He first learned assembly on the Timex/Sinclair 1000 . Since he couldn’t afford an assembler he would write the programs on paper, look up the opcodes in a table, and poke the resulting numbers into a BASIC string. He much prefers his AVR toolset.