Playing with AVRDude

I've been doing some prototyping with AVR micro-controllers and have learned a few things with AVRDude. First of all, AVRDude make it super easy to upload code to the microcontroller.

I have a super cheep USBasp.

All you have to do is connect the 10-pin header to the micro-controller's 6-pin ISP header. The USBasp will supply power to the micro-controller while programming.

Upload code to to microcontroller using AVRDude. This code will write the test.hex system image to the flash of a AVRMega328p using the usbasp programmer.

$ avrdude -c usbasp -p m328p -U flash:w:test.hex

I took the AVRMega328p chip from an Arduino board and initially had some problems uploading code to it with the usbasp. I discovered the problem was that the arduino chip came pre-programmed to use the 16Mhz oscillator to run the system clock. The system was refusing to program and run on my protoboard because I did not have it hooked up and external oscillator. To fix this, I used AVRDude to program the clock select fuses back to their default values. I found this page very helpful for choosing the correct fuse values: Atmel AVR Fuse Calculator.

Read current lower fuse bit values:

$ avrdude -c usbasp -p m328p -U lfuse:r:h

Reset fuses back to default values (using internal RC oscillator @8Mhz)

$ avrdude -c usbasp -p m328p -U lfuse:w:0x62:m

Paul Soucy

Read more posts by this author.