Thursday, 5 November 2015

Programming Standalone avr with Arduino as ISP without Bootloader

We all want to convert our working program into a standalone Project sometime in our "Electronics" Life. So here I came up with an simple but perfect way to do this.

We are going to Program an AVR Microcontrollers (which are supported by arduino IDE, you can add support if unsupported MCU by using extra core files)

Difficulty level : Intermediate
  • Should have a bit of knowledge about Arduino and Arduino IDE
  • Should know what is bread board and how does it function.
Arduino IDE Version at the Time of writing Blog : 1.6.5 

Components we need

Component Quantity
Arduino 1
AVR Micro controller 1
Crystal(16MHz preferred) 1
22pF Capacitor 2
Breadboard 1
Jumper M-M wires 6
Any common LED(for testing the Program) 1
220Ω to 1kΩ any resistor 1

Step 1

Program your Arduino as ISP.
For that follow these steps
  1. Open Arduino IDE
  2. Go to File Menu
  3. Examples
  4. Select "Arduino as ISP"
  5. Connect your Arduino board
  6. Select the Board from Tools menu > Board
  7. Select the Correct COM port it is connected to
  8. Upload the Program

Step 2

Connect the MCU
  1. Place the MCU on breadboard
  2. Remove Power for Arduino
  3. Connect the MCU with the given Pinout(ICSP connection)
  4. RECHECK the connections
  5. Power the Arduino board
ICSP Pins on Arduino
Uno or Duemilanove11121310
Mega1280 or Mega256051505253
Connect the reset pin given above(pin 10 for uno and 53 for mega) to the target IC reset pin

You can  Put an LED (with resistor) on the following pins:
9: Heartbeat   - shows the programmer is running
8: Error       - Lights up if something goes wrong (use red if that makes sense)
7: Programming - In communication with the slave MCU

for Example for UNO and ATmega168p

or can google for "Arduino isp standalone connection"

**Tip:** If the mega is not able to flash the IC as programmer, "Uncomment" the line number 81, which says "#define USE_OLD_STYLE_WIRING" , then you can connect 13, 12, 11 and 10 pin of arduino mega as the same pin shown above for uno.

Step 3

Verifying the connections.

Go to Arduino Installation folder (Typically "C:\Program Files (x86)\Arduino" for 64 bit Windows) in your OS File Explorer
  1. Go in hardware> Tools > avr > bin folder
  2. go in file menu and Open Command Prompt Here (your steps might change based on your OS)
  3. type "avrdude" without quotes and press "Enter"
  4. If lots of things are printed, that means you have found the program avrdude.exe, else you need to find or download and install one.
  5.  type the command
    avrdude -c Arduino -P COM4 -b 19200 -C "../etc/avrdude.conf" -p m328p
  • Change the COM4 to the COM port your arduino is connected to
  • -C "../etc/avrdude.conf" is used only when you are running from arduino folder, and not when  installed avrdude separately.
  • m328p is the name of Microcontroller to be programmed in my case "ATmega328p" whose codename is m328p
after you are sure you have done everything correctly,
you would see a line of ##### and then a line written as Signature = <something something>

this means you are connected perfectly with your mcu, 
If any error is there, please RECHECK the connections and google for the error, or ask me if nothing helps.

To simplify the process you can download the software, AVRDUDESS for windows 

You can see the setting done here

after everything is selected, press the Detect button on top right
It will show signature = <something something>
in the bottom black console part.

You can see a line written as " -c arduino -p m328p...."
that's what this software does, it writes the parameters for you.

Step 4

fuse bits.

You can read the Fuse bits using the "Read" button in fuse and lock bits section. For more information about Fusebits please refer to
We need the fusebits to instruct the microcontroller to use external clock source as the Crystal

WRONG fuse bits setting can make your device UN-READABLE!!!

so please follow other guides if you really don't know anything about fuse bits.

steps for setting fuse bits.
  1. Go to engbedded site (
  2. Select the Microcontroller you are using (in my case ATmega328p)
  3. In Feature Configuration section, edit the first drop down menu and go to the last option in that,
    "Ext. Crystal Osc. ...... [CKSEL=1111 SUT=11]"
  4. Uncheck "Divide clock by 8 internally; [CKDIV8=0]"
  6. Scroll down to "Current Setting" section
  7. Copy the "Low", "High" and "Extended" values from here to the avrdudess software "fuse and Lock bits" section in right centre
  8. Verify again if its in the same format as needed and exactly in the right "bits"
  9. Press "Write" button
  10. Wish for luck!
  11. Some ### will be written in black section(console)
  12. Press detect in top Right corner after "ready" is written in the bottom status bar
  13. If in console "signature = <something>" is written You are very lucky, the fuse bits are set successfully.
  14. If not, please verify everything and google the error if needed.

Fuse bit are to be set only once and not every time you flash a program.

Step 5

Programming the MCU.

  1. Open Arduino IDE.
  2. If you are mimicking an existing Arduino like me, you can select the appropriate board from Tools menu(in my case Arduino UNO as I am using ATmega328p at 16MHz)
  3. If not, then you need to add a board using tutorials below(off coarse you need to have core files for that MCU added as said in the start of this tutorial
  4. Go to File > Examples > 01. Basics > Blink
  5. Go to File > Preferences
  6. Check "Show verbose output during :" > "compilation"
  7. Compile the Program(Press the Verify button in arduino IDE Toolbar(the first one))
  8. See the bottom console section.
  9. You would see many things written.
  10. Find the address of the ".hex" file in the last 4-5 lines

    something like "C:\Users\test~1\AppData\Local\Temp\build2406314805678981373.tmp/Blink.cpp.hex"
  11. Copy this Link, this is the file in HEX form which we will flash in our Micro controller
  12. Paste this in the AVRDUDESS software "flash" section
  13. Make sure "write" option is selected
  14. Press "Go" button which is in the "Flash" section.
  15. After program is written, Connect an LED on 13th pin of the arduino through a resistor
    (13th arduino pin would be something different on your actual MCU)

    For me, Its pin number 19 on ATmega328p

    you can google for an image like this "arduino atmega328p pinout"
    (Yellow and Red is Arduino Pinout and normal 1,2,3... are actual pins on IC)
    So 13 arduino pin = B5= 19 pin on IC

Hope the LED is Blinking.

Step 6

Now you can use Arduino IDE to program the MCU.

  1. Open Arduino IDE.
  2. Make sure you selected your custom Board
  3. Go in sketch menu
  4. select Upload using Programmer

Congrats on your feat and lets have a treat.!

This Process is tested and verified several times, and on different systems. So I know its working, by any chance if you burn your Microcontroller, its your own responsibility, better to ask before you burn.!

For more tech stuff, Check my Website

No comments:

Post a Comment