loading

[THIS TUTORIAL IS OUTDATED. FOR A LATEST AND UPDATED VERSION, PLEASE VISIT THIS SITE]

Hey, I am riktronics , and this is my first instructable. Here I explained how to burn programs in your AVR microcontroller with an Arduino. By this, you won't need to purchase a costly AVR programmer if you already have an Arduino. And I guess you already have one.

Here you won't need any external crystal to be attached, neither need painful process to optimize "bootloader" for your standalone AVR. Just connect your arduino to microcontroller, and start uploading codes.

[NOTE: THE MAKEFILE LINK IS REPORTEDLY NOT WORKING. TO GET THE MAKEFILE, VISIT HERE]

Step 1: Things You Need. (not Much)

[THIS TUTORIAL IS OUTDATED. FOR A LATEST AND UPDATED VERSION, PLEASE VISIT THIS SITE]

1. A breadboard

2. 6 jumper wires and some extra wires.

3. An arduino board. ( I used arduino UNO)

4. a LED and a 220 ohms resistor.

5. 10 microfarad capacitor .(only if you are using older ardino boards such as duemilianove or NG, which don't have auto reset feature).

6. And of course the target AVR. Here I used ATmega8-16PU.

Step 2: Upload ArduinoISP Code on Arduino Board

The first step is the upload the ArduinoISP sketch to your Arduino to make it a programmer.It’s located under File >> Examples >> ArduinoISP. Ensure that the Board and Serial Port configuration is correct (under Tools), and then press Upload.

To check Serial Port, go to tools >> serial port. (for example, it may be "COM11 (arduino UNO)" ). note down that serial port number somewhere, soon you gonna need it.

Step 3: Open Command Prompt (in Windows OS)

When command prompt is opened, it will show you the root directory. it may be C:\> , or may be anything like C:\xx\yy\zz> . for me, it is C:\Users\Abhra Mitra> (see picture) . Whatever the root directory is, just note that down somewhere as very soon you gonna need it.

Step 5: Installation of WinAVR (only Help for Windows OS Is Covered for Now)

Start installing winAVR and make sure if all three dialogue boxes are checked while installing. Don'tchange the installation directory from the default one, that is C:\winAVR. See pictures..

Step 6: Opening Toolchain Apps ( MFile[winAVR], Programmer's Notepad[winAVR])

After installation done, you may wonder where the hell the installed software is gone as you can't see that on desktop. so, you need to "search" with key word "winavr". see the picture given. you will have multiple results. you need two apps, MFile[winAVR], and programmer's notepad[winAVR]. Ignore rest of them.

Step 7: Editing "MakeFile"

[GO HERE TO DOWNLOAD MAKEFILE AND SEE UPDATED TUTORIAL]]

Makefile is a file without any extension. It commands the compiler to upload the code according to target AVR's property and programmer's property. Hence, it's really really important to configure a appropriate Makefile. Without deep knowledge on AVR and C language, you can't make a Makefile. So I included a template. you just need to edit it as per your AVR IC.
1. Open MFile[winAVR].
2. now. Makefile >> Enabe editing of makefile >> (select it.).
3. now, File >> Open >> ( now navigate to where you have downloaded the Makefile).
4. now, you need to edit it. See the third image with red markings on it. Only the marked areas are needed to be changed by you. in "DEVICE" write your AVR's name. Here mine is atmega8. Yours may differ. If it's attiny2313, then write so. The "CLOCK" is set at 8000000 which implies 8MHz internal clock. Don't change it. Now come to "PROGRAMMER". you only need to change the COM port. I've told you in 2nd step to note down the COM Port number from arduino IDE. Just write that now. It may be COM4, may be COM3. Mine is COM11. Now you need to change the fusebit. Go to step4 and choose "fuse calculator" from my given links. A site will be opened named engbedded.com. there select your AVR type and fuses will automatically be generated (see last image. that is fusebit of atmega8). Just copy and paste that after "FUSES" option. Don't forget to delete my fusebit before pasting yours.

5. All done. now save the file to your root directory. Don't save it any different place.(In step3 I have told you to note down the root directory from command prompt. )

Step 8: Editing Main.c

Open Programmer's Notepad[winAVR]. Select C/C++ from drop down. (see image). Now go to File >> Open >> (now navigate to where you have downloaded the main.c file.).

Open the file. The code is set to blink a LED connected to PD6 PIN at 1 Hz frequency. I am not going to explain details about the code here, but you can learn C for AVR from ladyada or from youtube. and much more sites are available for learning AVR coding.

Actually you need not change anything in code now. It's just a hello world code. now go to File >> save as >> (now save it to root directory, where you have also saved the Makefile).

Note: Makefile and main.c must be in same directory. and the directory must be root directory that you have found in command prompt in step3.

After you have saved it, now go to Tools >> [winAVR]Make All >> (click).

Compiling is successfully done if you have not done things wrong. see the last image. If all is OK, then you can see it on programmer's notepad's "Output" window.

Step 9: Circuit Diagram

This is the minimum circuit diagram to program an AVR using Arduino. I have given circuits for three very common AVRs. ATMega328p, ATMega8 and ATTiny2313. But following thee below PIN connection, you can easily program any AVR.

PIN MOSI of AVR to digital PIN11 of Arduino.

PIN MISO of AVR to digital PIN12 of Arduino.

PIN SCK of AVR to digital PIN13 of Arduino.

PIN RESET of AVR to digital PIN10 of Arduino.

PIN VCC of AVR to 5V PIN of Arduino.

PIN GND of AVR to GND PIN of Arduino.

To know the PIN configuration of your AVR, go to Atmel's website. In search bar, type your AVR's name. now, choose appropriate search result and select "datasheet" option. Download it and open. there you can see the PIN configuration. I am giving here atmega8 datasheet and pin configuration.

You may need to add a 10 microfarad capacitor between RESET and GND PIN in Arduino, only if your Arduino is older version and doesn't support auto reset. but if you are using UNO R3. MEGA or any newer version, you will not need it.

Make the circuit on breadboard without any loose connection.(see last 2 images). {my circuit is already coded, so green LED on breadboard is ON}

.

Step 10: [TOUGHEST PARTS ARE COMING]

Now be very attentive and careful. Because, in following steps, we going to upload the compiled code to AVR using AVRDUDE. Urrgh, what is AVRDUDE? Okay, AVRDUDE is a command line software that comes with winAVR and makes the uploading process. To call AVRDUDE you need to open command prompt and then put correct commands to make it work as it is a command line software.

In AVRDUDE, we will define programmer type, AVR name, COM Port, baud rate (speed of uploading) and command to flash the defined .hex file.

Step 11: Know Your AVR's Code Name

You know your AVR's name, no doubt but you don't know it's code name which must be mentioned in AVRDUDE command line to upload the code. how can you know it? okay, you need to put a command, which will show you code names of all AVRs.

open command prompt >> (you can see the root directory is already written on screen) >> type the following code and press enter.

avrdude -c arduino -p xyz

It will open a chart of AVR names and corresponding code names.(see image 1).

now you know your chip's name. replace "xyz" after -p with your chip's name. If AVR is atmega8, command line will be,

avrdude -c arduino -p m8

Step 12: Set COM Port

I think you have noted down the COM Port already. Now make sure if your Arduino is connected to pc and AVR on breadboards is connected with arduino.

Now put this code on Command Prompt, (don't forget to replace my AVR's code name with your AVR's and my COM Port with yours COM Port). now press enter.

avrdude -c arduino -p m8 -P COM11

Again, type correct chip name and COM Port. Don't just copy paste this code.

Now it may give you a message like "your chip's signature is blah blah

expected atmega8 signature is blah blah and blah

check your chip connection or use -F to avoid it"

Do nothing. Just ignore it. Go to next step.

But, if you get any error message, fault is yours. double check all connections. set correct AVR name and COM Port.

Step 13: Upload HEX File to AVR

You are almost done. now it's time to upload the .hex code that is generated in root directory by programmer's notepad[winAVR] (at that moment when you have clicked on "make all" option).

Now in command prompt you need to put the command to upload the hex file (main.hex). use the below command but don't forget to change chip name and COM Port as per your AVR and PC, then press enter.

avrdude -c arduino -p m8 -P COM11 -b 19200 -U flash:w:main.hex

look at those images to get clarifications.

now you will see led on breadboard is blinking.

Done, code is uploaded.

Step 14: CONCLUSION

Linux and Mac users can get help from YouTube video by Michael Holachek (VIDEO CREDIT GOES TO HIM, NOT TO ME).

THANKS FOR READING.

[TO SEE MORE RECENT VERSION OF THIS TUTORIAL, GO HERE]

For beginners, an awesome guidance to get started in electronics can be found HERE.

<p>Hi everyone. This tutorial is updated and pubished in my site. All files are available there. Please visit https://riktronics.wordpress.com/2016/07/26/program-avr-using-arduino-simplest-way/#more-621 .</p>
<p>your site link not working. can you please check it again ?</p>
Dear, click the link on beginning of tutorial .. On &quot;THIS SITE&quot; text.. Or go to https://riktronics.wordpress.com/2016/07/26/program-avr-using-arduino-simplest-way/
<p>can't download makefile. I tried editing the makefile that comes with winavr and the one that comes with arduino ide, but neither of them work. maybe I need to go pro to download, but I won't pay $15 just to see if that's the problem and to get &quot;less advertising&quot;</p>
<p><a href="https://drive.google.com/file/d/0BwFDlFgwDpb0N3hvUWJjTlFDNXM/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0BwFDlFgwDpb0N3hvU...</a> </p><p>please check this link.</p>
<p>thanks. I got really angry because I've been stubbornly trying to program my avr chips without buying an avr programmer, for 3 days(about 10 hours/day) now, and this was the first time I actually searched for instructions, so I had to write that to calm down. I really didn't expect you to reply, so I really appreciate it.</p>
<p>please let me know if you could download makefile from my latest link or not.</p>
<p>I did. Thank you.</p>
<p>when I prove I receive this error:</p><p>peppino@peppinolnx:~$ avrdude -c arduino -p m8 -P/dev/ttyACM0 -F -Uflash:w:/media/peppino/&quot;TOSHIBA EXT&quot;/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex:a<br><br>avrdude: AVR device initialized and ready to accept instructions<br><br>Reading | ################################################## | 100% 0.00s<br><br>avrdude: Device signature = 0x1e950f<br>avrdude: Expected signature for ATmega8 is 1E 93 07<br>avrdude: NOTE: &quot;flash&quot; memory has been specified, an erase cycle will be performed<br> To disable this feature, specify the -D option.<br>avrdude: erasing chip<br>avrdude: reading input file &quot;/media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex&quot;<br>avrdude: input file /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex auto detected as Intel Hex<br>avrdude: writing flash (90 bytes):<br><br>Writing | ################################################## | 100% 0.03s<br><br>avrdude: 90 bytes of flash written<br>avrdude: verifying flash memory against /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex:<br>avrdude: load data flash data from input file /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex:<br>avrdude: input file /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex auto detected as Intel Hex<br>avrdude: input file /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex contains 90 bytes<br>avrdude: reading on-chip flash data:<br><br>Reading | ################################################## | 100% 0.02s<br><br>avrdude: verifying ...<br>avrdude: verification error, first mismatch at byte 0x0000<br> 0x3f != 0x12<br>avrdude: verification error; content mismatch<br><br>avrdude: safemode: Fuses OK (H:FF, E:00, L:00)<br><br>avrdude done. Thank you.<br><br>peppino@peppinolnx:~$ </p>
sorry to know you are gettig error. Can you please say whether you are using windows or Linux or Mac?<br>I can suggest you two things now, <br>1) remove &quot;:a&quot; (without quotation marks) from avrdude command.<br>2) add -V tag within command. add it before -U tag.<br><br>finally, again, let me know your OS. and also, are you using winAVR and followed my instructions line by line?
<p>Thank you!</p><p>I use Linux (Lubuntu) and I wrote you main with Eclipse that has a plugin for AVR device. I configure the project under this IDE following your instructions (device atmega8, clock 8000000, fuse). I proved to send the skecth with Eclipse or using avrdude from a command line but the result is the same.</p><p>Now with your suggests I think that the fuse is correctly written but the flash memory don't. Here is the response.</p><p>peppino@peppinolnx:~$ avrdude -c arduino -p m8 -P/dev/ttyACM0 -F -V -Ulfuse:w:0xe1:m -Uhfuse:w:0xd9:m -Uflash:w:/media/peppino/&quot;TOSHIBA EXT&quot;/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex<br><br>avrdude: AVR device initialized and ready to accept instructions<br><br>Reading | ################################################## | 100% 0.00s<br><br>avrdude: Device signature = 0x1e950f<br>avrdude: Expected signature for ATmega8 is 1E 93 07<br>avrdude: NOTE: &quot;flash&quot; memory has been specified, an erase cycle will be performed<br> To disable this feature, specify the -D option.<br>avrdude: erasing chip<br>avrdude: reading input file &quot;0xe1&quot;<br>avrdude: writing lfuse (1 bytes):<br><br>Writing | | 0% 0.00s ***failed; <br>Writing | ################################################## | 100% 0.03s<br><br>avrdude: 1 bytes of lfuse written<br>avrdude: reading input file &quot;0xd9&quot;<br>avrdude: writing hfuse (1 bytes):<br><br>Writing | | 0% 0.00s ***failed; <br>Writing | ################################################## | 100% 0.03s<br><br>avrdude: 1 bytes of hfuse written<br>avrdude: reading input file &quot;/media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex&quot;<br>avrdude: input file /media/peppino/TOSHIBA EXT/personale/elettronica/eclipse/workspace/embeddedC/Release/embeddedC.hex auto detected as Intel Hex<br>avrdude: writing flash (90 bytes):<br><br>Writing | ################################################## | 100% 0.03s<br><br>avrdude: 90 bytes of flash written<br><br>avrdude: safemode: lfuse changed! Was e1, and is now 0<br>Would you like this fuse to be changed back? [y/n] n<br>avrdude: safemode: hfuse changed! Was d9, and is now 0<br>Would you like this fuse to be changed back? [y/n] n<br>avrdude: safemode: Fuses OK (H:FF, E:D9, L:E1)<br>avrdude: stk500_recv(): programmer is not responding</p>
I am really illiterate in Linux, sorry.<br>Anyways, I think it's not required to mention the fuses in command line if you have already specified in Makefile. So, now question is, have you configured the Makefile correctly with fuses??
<p>EUREKA!!</p><p>thank you for your help: we win!!</p><p>this is the command I used: </p><p>avrdude -pm8 -carduino -F -V -P/dev/ttyACM0 -b19200 -Uflash:w:embeddedC.hex:a</p><p>I also added a 10uF capacitor between Arduino reset and GND, I read it is necessary for some O.S. </p><p>It work and the blink sketch work correctly.</p><p>I can use also the function of ECLIPSE that load the .hex on the MCU and all is right.</p><p>If you need details about ECLIPSE configuration ask me</p><p>excuse me for my poor English </p>
<p>dear, happy to know you got success. but since late night, I am getting same error as you once got. Really frustrated. Can't figure out what to do. ?</p>
<p>sorry for you!</p><p>I am not very expert, I could suggest to put a 10uF from reset to GND and control all the connections </p>
Thanks Marc. please let me know if it worked for you. ?
<p>Great! I've been trying some ways to program ATMega16, definitely gone try this one too! </p>

About This Instructable

10,419views

31favorites

More by abhra0897:Programming AVR with Arduino as ISP without bootloader and external crystal 
Add instructable to: