Monday, August 24, 2015

How to Program/burn/flash a AVR microcontroller(Step by step tutorial)

Here we go.....
Things required
  1. Atmel AVR Studio
  2. USBasp(Its about 230Rs in India (2$ in US i think)[Search for "usbasp" on ebay if you don't have one]
  3. AVR Burn-O-Mat(This requires Java)
  4. WinAVR
  5. And of course,the micro to be programmed!
Step 1:
   
    Download and install the Atmel AVR Studio


    I had already installed it so.....this showed up


I won't bother uninstalling and reinstalling. I assume everyone is familiar with installing windows program(even a baby can do it,its that simple). The installation takes a few minutes so be patient.


Step 2:

          Once you've finished installing AVR Studio. The next thing to do is to download and install 
WinAVR. I haven't installed it yet so I'll be able to show you the process!




  Install the program by clicking Next,I Agree and Install



 After the installation completes,click Finish to exit installer.

Step 3:

          Download and install AVR Burn-O-Mat






         Tick "Launch AVR Burn-O-Mat" and click "Finish". If the program launches,it means you already have Java installed(You can skip the Java installation). Others will the get the following message that I get since we don't have Java installed.


 Press OK. Download and install  Java.






         Run the file.



Let the download complete.


  UNTICK the sqaure box.


Click next and the installation begins.


  This completes step 2.

Step 3:

          Buy a USBasb programmer(It's really inexpensive considering the price of Arduino boards)
 Connect it to the computer. Now we'll have to install the driver for it. Download the drivers from here.
This is how to install them...



 Extract the zip file


 Go to My Computer(Windows XP/Vista/7)/This PC(Windows 8.1/10)


Right Click and Properties



  Go to Device Manager


In Other Devices > USBasp
 Right Click and select Update Driver Software


 Select Browse my computer for driver software


Enter the extracted folder path.



 Click Install this driver software anyway.



 You're done with configuring of USBasp. Yay!!

Step 4: Configuring AVR Burn-O-Mat

Go to C Drive and rename "WinAVR-20100110" to "WinAVR".




  Next run AVR Burn-O-Mat.




Select USBasb from the list,apply and ok and you're done with configuring everything. Now you can program a AVR micro.

Step 5: Finally connecting the micro and writing a blinking LED program


Follows the diagram for the connections.
After doing the connections on a breadboard this is how it looks



 OK. Now the connections are done
Now lets write the program.
Start AVR Studio.


 

 And this come up. Allow internet access to AVR Studio by ticking both the boxes.



Click New Project and it will start making the Project file.



You can either make a C/C++ or Assembler Project. Here I'm going with Assembler.
Give the project any name you like. In my case, I named it "Firstone".


Select the micro that you are programming in my case Atmega8.


This is assembly code to blink a LED at 1.9 Hz(You'll have to read the device datasheet to understand the code) The Assembly language is micro dependent. So the above code cannot be used with micro other than Atmega8.

Here's the C code with is micro independent(not in all cases though). Since I'm using the internal timer2 to generate the blinking, this C code will only work with micros that have timer2.


Next, After writing the code,Build it by pressing F7


If there were no syntax error,it'll build successfully.


Start AVR Burn-O-Mat 
Tell the location of hex file
It's stored in the Documents folder.
In Documents>Atmel Studio>6.2 Here you'll find your project folder.


This is final button. Before you press it check if all connections are proper. And the circuit is connected to USB.
Press the write button!!!!
If the led starts blinking you were succcessful 
Congratulations!!!
If not, you must have made some connection error. Refer the tutorial and try again!!
Hope you succeed.


Here's the video showing the blinking LED!!. Didn't work first time though. Missed a instruction
This one
ser r18
out ocr2,r18
But worked after including that. Yay!!!

1 comment: