How to Upload C Code to ِAVR Using Arduino Uno As Programmer

by alaa naser alnasef in Circuits > Arduino

1521 Views, 1 Favorites, 0 Comments

How to Upload C Code to ِAVR Using Arduino Uno As Programmer

atmega-16.png

HI everyone :D

Here I will share a simple way to program any AVR chip using Arduino Uno R3

All you need to burn the code to your microcontroller is Arduino Uno instead of buying specific programmer which cost a lot.

Supplies

You will need:

  1. Arduino uno r3 with removable chip (1)
  2. Jumper wires
  3. 10uF electrolyte capacitor (1)
  4. Hex file generated from your C code

Arduino ISP

Annotation 2019-12-27 224158.png

First: open your Arduino IDE and upload Arduino ISP into your Arduino

you can find it in File -> Examples

Before pressing upload key you need to check the Board type and COM port.

NOTE: this code will turn your Arduino to a programmer!

Find the Datasheet for Your AVR and Check the Pin Out

Annotation 2019-12-27 224658.png

Pin 1 is the pin that have a small dot near it

we need (VCC, GND, Reset, UCSK , MISO , MOSI) locate them in your AVR.

Connect Arduino to AVR

avr dude connection.jpg
Annotation 2019-12-27 225402.png
photo_2019-12-27_23-08-17.jpg

connect Arduino to AVR according to the Figure and your AVR datasheet

and don't forget to connect a 10uF capacitor between GND an RST of your Arduino for disabling the auto reset of Arduino

Get Your Fuse Setting and AVRDUDE APP

Annotation 2019-12-27 233248.png

go to

http://www.engbedded.com/fusecalc/

and select your AVR, mine is Atmega16

I won't change anything so I don't destroy my AVR, but I will change the internal RC to 8 MHZ "You can choose external 16 MHZ crystal" it's up to you.

scroll down and copy avrdude argument

to paste it into AVRDUDE programe.

mine is

-U lfuse:w:0xe4:m -U hfuse:w:0x99:m

AVEDUDE download link:

http://download.savannah.gnu.org/releases/avrdude/

then open it and change the settings like the image and depending on your hardware and don't forget to paste the fuse settings into Additional command line args

Get Your HEX File From Your C Code

Annotation 2019-12-27 234044.png

I will write a simple c code to blink a LED in PIN 20

upload hex file to avrdude in Flash section and hit program

The End

December 27, 2019

For any question comment down below