Wednesday, October 8, 2008

Programming a .hex file with AVR Studio

If you just want to write an existing program to your Atmel AVR chip, without changing any actual code, you need a precompiled .hex file (a hex file is a compiled version of a program, to work on a specific microcontroller)

If you have a ATTiny45 or ATTiny85 you can Download here a precompiled .hex file for my 1-key-keyboard project. For other microcontrollers you’ll need a .hex file which is compiled for it.

Connect with AVR Studio to your device by pressing the connect button connect.jpg and selecting your programmer from the list and connect.

Before programming the actual firmware, the fuses need to be set on the AVR.
Read more about fuses here

If you’re using my 1-key-keyboard .hex file, the easiest way to get the correct setting is to change the bottom 3 values to:

EXTENDED: 0xFF
HIGH: 0xDF
LOW: 0xC1

Then press “Program” and the fuses are set! (this has to be done only once for every chip, unless you want to change these fuse settings off course)

See the picture below for the correct settings



fuses.jpg



Now you’re ready to program the actual .hex file on the AVR.

Go to the Program tab and under “Flash” select the path of the capslocker.hex file and press “Program”



programming.jpg



If everything goes correct, the ATTiny is programmed and you get the following report (only last 5 lines visible without scrolling)

Getting isp parameter.. SD=0×0a .. OKOK
Reading FLASH input file.. OK
Entering programming mode.. OK!
Erasing device.. OK!
Programming FLASH .. OK!
Reading FLASH .. OK!
FLASH contents is equal to file.. OK
Leaving programming mode.. OK!



Now you have successfully uploaded the code to the AVR!