Programming AVR chips

Written by Walter on A few weeks back I bought a cheap diy <a href="http://www.ladyada.net/make/usbtinyisp/"> avr programmer kit for 18$ from adafruit </a>. If I go to my local electronics shop and just buy the parts its still more expensive than 18$ making this kit a great deal! Also you don't have the chicken/egg problem where you need a programmed avr attiny 2313 to get your usb-programmer working which programs avr chips :).



Note to self: Remember the make_key_project in Desktop/USB_AVR_Programmer folder!



Yesterday I received my parts


and after about an hour I finished soldering the kit:




Setting up my toolchain in Mac OS X for programming avr chips turned out to be a breeze too using OSX-AVR. Here is a little demo video of me overclocking an attiny 2313 from 8Mhz (internal oscillator) to 12Mhz using an external chrystal.


This is usefull since running the attiny 2313 at 12Mhz allows using tinyusb firmware. Which gives you usb capabilities for these cheap chips (3 euro a pop). This firmware is also used inside the usb-avr programmer itself. If you reverse the video and compare the flashing of the led before/after chrystal is used you can clearly see it flashes faster with the 12Mhz chrystal than with running the internal 8Mhz one :).

Here are the sources for my ledflasher demo:
ledtest.tar.gz

The Makefile is set up so you can do:

make -> compile led.c into led.hex using avr-gcc toolchain
make flash -> flash new hex file to chip
make fuse -> flash new fuse bits to chip (for external 12Mhz chrystal)
make fuse_internal -> fuse bits that use internal oscillator

To read about the fuses, and the instruction set of the avr chips etc can all be read in the extensive datasheet here
Ow and yes before I forget. This is the pin configuration of the 6 and 8 pin plugs that come out of the programmer :

By looking at the datasheet you can figure out easily where to put them (as you see on the breadboard youtube video). Vcc and GND go to pins 10 and 20, etc...

To use the tinyusb based programmer. You need a patched version of avrdude (copy binary and config file over the original installed by osx-avr in /usr/local/avr/bin):
avrdude binaries
You might have problems with the target .hex file being too large. This is with latest avr-gcc's. To circumvent the problem choose an earlier OSX-AVR release with a gcc 3.x compiler. The 3.x compilers generate smaller code (but sometimes use more stackspace).

This is the usb sourcecode which allows to flash a regular avr chip so that it runs the usb protocol on two pins assigned to D+ and D-:
usbtiny firmware

Good tutorial to get into the avr or catch the microelectronics addiction can be read here:
avr crash course

Stuff you can do with usb enabled chip, include switching on mains appliances like so:
usb power switch

Get temp, humidity sensor data to your pc:
sensors on usb


Note to self: Remember the make_key_project in Desktop/USB_AVR_Programmer folder!


Some people even hack together professional domotica with the avr chips. This man is constructing his own wireless dimmer implementation based on the attiny 2313

That's all folks, happy hacking!

Back to archive