All you AVR user fraternity out there, and those just entering the stream, Some of you started with PIC microcontrollers and some started with ATMEL AVRs, this is written for you !
So you bought a USBASP because its cheap and effective to flash the ROM on your Atmega device, or maybe the ATTINY range. These can be obtained for under 5$, as chinese clones of the Open source USB-ASP ! AVRdude is the software to program them.
You undoubtedly know how to generate a Hex file using the Atmel Studio (I still use AVR Studio v4.19 instead of the latest v7 because its snappier and faster on my light single core CPU laptop)/ Netbook and WINAVR install if you are reading this.Anything written in DotNet runs SLOW ! and the later versions are designed to make your laptop run like a tortoise ! You can use Studio v4.19 the greatest version of Studio from ATMEL for AVR microcontrollers, switching over to version 7 when you really need it for the later chips, and make your time on the laptop more productive, working instead of waiting ! This is what I recommend.
A typical AVR dude command line to program an Atmega with a Hex file, runs like this:
WRITE TO FLASH :
AVRdude -s -c avrisp -p t44 -P usb -U "flash:w:D:\ARDUINO\pwmeg1.hex:a"
here pwmeg1.hex is the Intel hex file to be "burned" or "flashed" into the "target MCU" in microcontroller Lingo.
That's a mouthful to remember ! You could write a batch file and run it in the command line in windows , naming it write_flash.bat. Similarly for reading the fuses, another mouthful of a line to remember ! It gets tedious.
for read flash + eeprom:
AVRdude -s -c avrisp -p t44 -P usb -U "flash:r:D:\ARDUINO\pwmeg1.hex:i" -U "eeprom:r::i"
The solution is to use one of the user friendly GUI front-end tools to AVRdude like Bitburner, Khazama programmer, which are nearly similar in merit. eXtreme Burner. I have used the free to use tool : eXtreme Burner a lot , its versatile, reliable, and this tutorial is about that. It can not only flash your hex file / program to the MPU , using commands issued to AVRdude in the background, it can also help you to set the FUSES which is a complicated subject that often confuses beginners to AVR programming. Here is a link to an excellent tutorial on the subject of FUSES that you can go through or brush up on. A word of caution: ATMEL uses '1' state of a FUSE bit to indicate its 'default' state ( unset or unprogrammed state) and '0' to indicate its programmed or set or activated state ! This is just opposite of what you do with FUSE bits in a PIC microcontroller. Be careful when you modify the clock fuse bits like making the internal RC clock change to external crystal because this will create problems in connecting to the chip without an external crystal set-up. Similarly be careful when you change state of critical fuse bits like SPIEN and RESET DISABLE (these should always be set to SPIEN = 0 and RESET DISABLE = 1 if you wish to continue communicating with the MCU with your USB-ASP in ISP / SPI mode ! If you botch this up you will need a High Voltage programmer to 'unbrick' your AVR.
If you are wondering "what the heck are fuses" and "what do they do" ? Read this excellent write up :
Another related topic is how to set the Clock speed of your AVR MPU which is capable of speeds from 1Mhz upto 16 or 20Mhz. There is also a lspecial ow power low frequency crystal option 31.25kHz which if properly designed can make your AVR run off AA batteries for 3 months !
Both these, Clock Fuse bits (both frequency and Type of clock internal RC/external crystal, and other Fuse bits) can be set through the FUSES tab in eXtreme Burner. First we will show you read the ROM, and then how to flash the hex file using eXtreme Burner. Of course, you could use the online AVR fuse websites too, but the option I explain can be used when you are offline too, anywhere.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Settings to Be Made:
The pictures show the SETTINGS to be done before you start your work. (its one time only). Under 'Hardware settings' sub-menu item, we select 375Hz because most of the MCU from ATMEL factory are set to Default settings of 1 Mhz CPU clock on internal RC oscillator. The ISP speed is a Quarter of F_cpu. That gives us 375 Khz nearest speed, you could go to a lower speed too, it won't make much difference. You could try to connect leaving this at its default, and issue a 'read all' , if it fails then you could come over here and alter the speed, making it lower.
Because if you are unable to connect (the message would be given in the programmer window "unable to communicate with chip, can't SCK" means the clock signal from your PC couldn't synchronise with your chip that you are trying to read or program)., you would be unable to change the Clock speed of the CPU or alter its speed and type ! So connecting is the basis of everything ! Its like "FIRST CONTACT" like you see in the Spielberg movies. If you succeed in this, you can always increase the clock speed of your MCU by programming the fuses accordingly, and later on use a higher speed to connect.
So go through the hardware settings snapshots provided here, then set the device type too (the chip you are trying to program, its model number).
Step 2: Setting Your Device Type
see the screenshot, Pic 1, we have set "ATTINY44A". This is a 14 pin Microcontroller sans UART. I have been using this recently, the SSU version. If you installed Extreme burner stock version you won't see Attiny44A in the device selection drop down list, you will see an Attiny44 which for all purposes we can use to program out Attiny44A too, to introduce any device not listed in this drop down list, read my other instructable "Hacking eXtreme Burner".
I have been using Atmega88PA-AU also with eXtreme Burner but in this Instructable we mention "Attiny44A" everywhere. Now how do you make a breadboard version of the tiny 7mm square SMD chip and test it with your programs ? (see the pics which indicate the chip size), For this, see my other instructable where I demonstrate how to make Breadboard suited Plug-in Modules using the Attiny44A-SSU and ATmega88PA-AU
Once you learn this technique you would be able to check out any chip you are curious to tinker with, whether its SMD or DIL package. For instance , I have even used a SMD chip coming in a 32-pin 0.8mm pin pitch Quad package (Atmega88A) in similar manner !
. Or you could just use the 28pin DIL version of the Attiny44A for this Instructable or whatever AVR you are using at the moment to try out eXtreme Burner for AVR programming..
Step 3: Issue a READ ALL or READ FLASH
Connect your USBasp to the USB port of your laptop, I assume you have already loaded the correct drivers that came with your programmer and that its correctly detected. It should appear under 'Devices and Printers' in windows start menu if it were , as soon as its plugged into the USB port ! Connect your target chip on its board with your USBasp (relevant SDI// ISP pins using 6 pin or 10 pin cable has to be connected between the two, namely the pins: MOSI,RESET, MISO,SCK, Vcc, Ground).
Issue a READ ALL from the MENU of Xtreme Burner. See pics and messages we obtained. Initially your screen showed 'FF' for ROM in First TAB of the burner, after read all it will show the actual ROM contents on the chip. If you used a factory fresh chip or an erased chip you would see FF in the contents after a "Read All". An unprogrammed chip will show 'FF' in its memory , so does an EEPROM (second tab in the programmer), the last tab shows the FUSES.
After a READ ALL the 3 tabs would show the correct information contained in the chip. Before that it would't, so issue a Read all first as soon as you connect everything.
Step 4: Write to Flash (your Hex File Flashed Into ROM on the Chip)
Select a file using the Browse dialog that opens when you click on the first icon in the MENU bar above. We selected one file as you see in the pic. Once you select the hex file (intel hex format) the Menu bar which showed "no file loaded" changed to file name that you loaded.
Now Issue a Write--> Flash from the Menu of the software. The messages will show you what is happening. see the pics.
After a successful write, you would see the 'FF' that mark a fresh or erased ROM change to what your program or hex file contains. The size or number of bytes that your file occupies in the ROM is also known to you by looking at this screen, which shows you the actual ROM contents of your target chip that you flashed just now.
The verification step is also done by reading the chip, as per the SETTINGS we did in first step. This is seen in the messages that verification was also successful.
Step 5: FUSES: How to Set Them in EXtreme Burner
When you issued a READ ALL the fuses were read from the chip. Thats the FIRST pic shown fuses.jpg.
Now perhaps you need to change them to something else. The fuses consist of 4 boxes in the last TAB on your eXtreme Burner screen. Namely LOW FUSE BYTE, HIGH FUSE BYTE, EXTENDED FUSE BYTE , LOCK FUSE BYTE and CALIBRATION BYTE. in that order they are shown .
You could simply use an ONLINE fuse calculator and fill them in. like the one at
Or you could use eXtreme burner to do it for you. offline itself anytime: Select from the drop down list that appears when you click on the DETAILS button that is there below each kind of fuse byte. Just double click on any line in the DETAILS screen and watch it change from SET to CLEARED and toggle its state with your mouse click on each line. The Fuse Byte in the box above it would change accordingly.
If you are wondering "what the heck are fuses" and "what do they do" ? Read this excellent write up :
Step 6: Setting Fuses Using EXtreme Burner Fuse Calculator
You can see the Details Screen that appears for each of the fuse bytes (LOW, HIGH, EXTENDED, LOCK, and Calibration). The Calibration byte should be left unchanged as it shows the calibration data byte in the AVR that applies to the internal RC oscillator. The LOCK byte is usually FF only, (not discussed in pics above) as you would not be locking the Flash or EEPROM while in learning stage. You would be changing only the LOW, HIGH and EXTENDED bytes. Be careful !
If you change SPIEN bit to 1 (unprogrammed state is 1 in AVR microcontrollers) you would be unable to communicate with your chip using USBASP or any programmer ! The default state is also shown in your screen for each fuse bit. This alerts you that SPIEN default is always 0 (programmed state) to allow you to use SPI mode for ISP programming. Debug-wire or DW bit is always left 1 (unprogrammed) when SPIEN is set to 0. This is its default state too. Also, in Extended Fuse bits 'Self Programming Enable" should be '1' (unprogrammed) if you are using your USB-ASP to program your target chip (not using bootloader ROM like in ARDUINO).
You can change the CLOCK bits (3 in number) to select internal RC or external crystal. I normally leave it for internal RC which allows you to get 2 extra pins that freeing up the external crystal entails to use as PORT pins for your AVR projects. Usually external crystal is needed when you need high accuracy timing in your project. For learners internal RC is enough.
Usually once you settle on some fuse combination you would not be changing it. It would be one-time. You would be only flashing the ROM or sometimes the EEPROM too. For Flashing the EEPROM separate .eep file is generated by your WINAVR / ATMEL studio if at all your program uses the EEPROM to store data. Otherwise the EEPROM is left unused, filled with the 'FF' data that shows 'NO DATA state ' of EEPROM.
Step 7: Final Value of Fuse Bits
After setting all the Fuse bits, and closing the DETAILS boxes that you used, you can see the value of the Fuse bits as calculated by the program (see pic) . All that remains is to issue a "Write --> Fuses" using the menu.And look at the messages that report a successful write. Later, you could also issue a READ ALL from the menu and check if the fuses read in last TAB of the burner screen coincide with what you wanted to write to the chip. (Fuse verification).
You would notice that at the start of this Instructable when we did a READ FUSES, the screen shows the same FUSE values that we see here ! That's because these are the fuses I often use and rarely change them once I set them in my MCU, unless I change the frequency from 1 Mhz to 4Mhz for some projects. The AVR can be set to 20Mhz maximum (some chips only upto 16Mhz ). The frequency you set for F_cpu also depends on the Voltage you supply the chip with ! For instance if your chip operates from 1.8V of Vcc upto 5.5V of Vcc (data sheet refer) you would not expect to run your Chip at 20 mhz if you supplied only 1.8V to it ! you are expecting too much from it ! A table in the data sheet tells you at what voltage the freq tops off at which figure. The higher your frequency of chip operation, the more the heat and more the power it consumes. Think of the Frequency like the Heartbeat of an animal. A Hummingbird with a high rate of hearbeat would have a higher energy burn per minute compared to a Whale or elephant with a much lower heartbeat ! But then it can do much more in a shorter time. The MCU is just like that.
Step 8: Finish
Now you have completed all the steps in eXtreme burner, you have read a chip's ROM, ou opened a HEX File and flashed it to the chip and verified the flash was OK, you also learned how to set the fuses and flash them to the chip.
If you have any questions, i will be glad to answer or modify the tutorial to make it clearer.
For some chips you may find its entry is missing in the chip selection dropdown list in the menu. Or you may face write errors and verify errors. In such cases please read my other Instructable "Hacking eXtreme Burner" to solve the issue.