Wednesday, 30 January 2013

Fun with Arduino - The Arduino as ISP

Time to BURN!


In the previous tutorial, we learned how to build a 'stand-alone' Arduino circuit on a breadboard using an ATMEGA328P microcontroller and some supporting components. That's all fine and good, but we need the ability to upload programs to the bare microprocessor for it to actually be useful.

This can be done in a few ways:

- Program the ATMEGA in the Arduino and pull the chip - (Not very convenient)
- Buy an AVR programmer - ($$$$$)
- Use the Arduino Board as a programmer

In this tutorial we are going to go with the last option and use the Arduino board that is conveniently sitting right in front of you as an ISP.

Once again, a Video is worth a thousand words:

 

What is an ISP?


ISP stands for 'In System Programmer'. This is a device that lets you upload code into a Microcontroller without removing it from the circuit. There are several types of ISP's ranging from inexpensive home-built circuits to expensive stand alone field programmers that don't even need a computer.

What is the SPI?


SPI stands for 'Serial Peripheral Interface' Bus. This is a communication standard introduced by Motorolla as a way to transfer data between digital devices. We will use this to connect the Arduino board to our breadboard microcontroller.

You can read all the gory details about the SPI here, but this is the minimum you should know. SPI works by categorizing devices as Masters or Slaves. A Master device can be connected to multiple Slave devices. The master also decides which slave to talk to and is in charge of starting communication.

An SPI connection requires four wires:

SCLK - 'Serial Clock' - This is the clock signal that synchronizes the two devices.
MOSI - 'Master Output, Slave Input' - The data line from the Master
MISO - 'Master Input, Slave Output' - The return data line from the Slave to the Master
SS - 'Slave Select" - This line is used to determine which Slave device is listening

To Bootload or not to Bootload?


Whenever you upload a sketch to an Arduino, you are using the Bootloader.  The Arduino Bootloader is a small program that permanently lives on the Arduinos' microcontroller. It allows the Arduino to communicate with your computer and download programs.

Since we are using the SPI interface to program the chip, we don't need the Bootloader. In fact, as soon as we upload our first program over the SPI, the Bootloader will be overwritten.

Even though we don't need the Bootloader anymore, It does have one useful trick. Each AVR microcontroller (inluding our ATMEGA328P) has a small chunk of permanent memory called 'Fuses' that control how the chip will behave. These Fuses need to be set in a specific configuration to make the chip Arduino compatible. When you buy a brand new ATMEGA chip from your favorite electronics store, they may not be set correctly.

When you 'Burn the Bootloader' to a chip, part of the process includes setting the Fuses. It is a dead simple way to configure a new chip. (See video for details)

You should now be comfortable using the ATMEGA328P chip in a stand alone circuit and can finally let your Arduino board move on to the next project.

Enjoy.

36 comments:

  1. Thanks for these tutorials. Very clear and helpfull. I bookmark your page.

    ReplyDelete
    Replies
    1. Thanks! Glad you found them useful. Welcome aboard!

      Delete
    2. Wonderful work!!!

      Thank you so much

      Delete
  2. EB / 2013-04-01
    Thanks for these two viedoes on how to initialy and easy use the Arduino to both program and use as a programmer.

    I don't think the crystal is needed as the fallback(internaly) frekvens is 8 Mhz with a divider of 8 so it's running about 1 Mhz by it self which should be as vel.

    ReplyDelete
    Replies
    1. Thanks for the insight. I was thinking that as well but was concerned that changing the clock frequency might create problems with some time dependent Arduino libraries. If you try it, let me know what you find.

      Delete
  3. very, very useful tutorial. and by the way, you just have created "THE WAY" to make videos, very clear, very didactic, no horrible music, I love you man!!!

    greetings from Mexico!!!

    ReplyDelete
    Replies
    1. Thanks HB!! Probably the nicest comment I've ever received. I'm glad you found my ramblings helpful.

      Delete
  4. i received message,

    avrdude: Expected signature for ATMEGA328P is 1E 95 0F
    Double check chip, or use -F to override this check.

    using arduino uno rev3, and atmega328p-pu

    ReplyDelete
    Replies
    1. Hi Illison. What version of Arduino IDE are you using?

      Delete
  5. hi, i'm using an ATMEGA328 not (atmega328p)
    and when i hit "upload using programmer" i get this error

    avrdude: stk500_getsync(): not in sync: resp=0x0a

    can you help me with this... thank you,

    ReplyDelete
    Replies
    1. Hi Mark

      That sounds like a communication problem. It might have something to do with the 328 having a different signature in avrdude than the 328p. Check out the following link http://forums.adafruit.com/viewtopic.php?f=22&t=26707

      Delete
    2. hi Dave,.! good news,

      after 3 days of hustling this 328 not(328p)
      I've final tamed it,.. there are only minor configuration in the avrdude, then BOOM,... i can now upload sketches using UNO,..

      Delete
  6. hi dave,

    thanks for your reply,but i didnt help me at all,..
    maybe the arduino uno is not a compatible on programming the 328,....maybe the duemilanove is the right board on programming the 328,....

    ReplyDelete
  7. Great videos and amazing explanation.

    ReplyDelete
  8. it shows following error :

    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
    avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude: stk500_disable(): unknown response=0x12
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
    avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude: stk500_disable(): unknown response=0x12
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
    avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude: stk500_disable(): unknown response=0x12
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
    Build options changed, rebuilding all


    what is this avrdude not in sync stuff....please help!

    ReplyDelete
    Replies
    1. Hi There. The stk500_getsync() error means that the software cannot communicate with the Arduino board. Perhaps you can provide some info:

      What type of Arduino board are you using?

      What software version? What COM port is selected? What board type is selected?

      Can you upload the "Blink" example program to the Arduino?

      What is the exact part number printed on the chip you are trying to program?

      Have you tried burning the Bootloader to the chip?

      Delete
  9. i uploaded arduino isp....i made a blink program on winavr for atmega8A and tested in proteus its fine...in avrdude i'm getting the signature of atmega328p(ARDUINO) not atmega8A how to program atmega8a using arduino isp and avrdude

    ReplyDelete
  10. How can I program ATMEGA only with arduino board

    ReplyDelete
    Replies
    1. Hi Giorgi. Unfortunately you cannot use an Arduino board to program its own chip. You need two Arduino boards or one Arduino and the circuit described in this tutorial (One board for programmer and one for the target).

      Delete
  11. Hello , I have the 1.6.5 software version, an Arduino Uno board and a ATMEGA328P-PV Chip and I when I try to burn bootloader it says :
    avrdude:Yikes! Invalid device signature.
    Double check connections and try again, or use -F to override this check.

    What is -F?

    When I try uploading to the chip is starts okay. "...Global variables use 265 bytes (12%) of dynamic memory, leaving 1,783 bytes for local variables. Maximum is 2,048.

    then, in red

    avrdude:Yikes! Invalid device signature.
    Double check connections and try again or use -F to override this check.

    I have re-done connections, switched all parts to make sure none were mal functioning or burnt (including the atmega chip) and still getting errors.

    My eletrolytic capacitors are 50v. Im not sure what difference that makes..

    How can I get this to work?

    ReplyDelete
  12. I get this message when trying to burn bootloader

    but the led light blinks along with the arduino board 13 led

    Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"

    avrdude: Error: Could not find USBtiny device (0x2341/0x49)
    Error while burning bootloader.

    ReplyDelete
  13. Do you need the microcontroller sitting on the Arduino board or can you use it as the one being ISP programmed on the breadboard after you upload the "ArduinoISP" example?

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. I am getting real time delay which is 15 times more than what i have programed for. in blinking led example i am getting almost 15 sec delay. why this is happening.

    ReplyDelete
  16. Hi, super tutorials thanks! I'm having an issue uploading the bootloader. This is the error I get:

    " This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    Arduino: 1.0.6 (Mac OS X), Board: "Arduino Diecimila or Duemilanove w/ ATmega168"
    ***failed;
    avrdude: verification error, first mismatch at byte 0x0000
    0x3f != 0x00
    avrdude: verification error; content mismatch"

    Do you know what I'm doing wrong?

    Thanks so much, can't wait to get the synth up and running!

    Dave

    ReplyDelete
    Replies
    1. The board type is set wrong. You need to set it for ATmega328 instead of ATmega168. Look for this in the Board menu on the arduino IDE

      Delete
  17. Is there any need to connect the capacitors externally while burning bootloader?

    ReplyDelete
  18. Is there any way to use arduino as isp to an PIC 16FXX FAMILY

    ReplyDelete
  19. Is it possible that this circuit on breadboard can run ultrasonic sensor and Bluetooth module as an Arduino UNO? Thanks

    ReplyDelete
  20. It's a very useful tutorial. Very easy to understand. But still I do not understand one thing. Can you program the ATmega328 even if other parts like LEDs, other ICs, pullup resistors are connected to pin 17, 18, 19?
    Or can you only program the ATmega328 alone as it is described here in you tutorial without any other connections.
    Thanks,
    Haruto

    ReplyDelete
  21. I am working on project and i have to use at89c51 microcontroller. I want to use Arduino as isp to program at89c51. Plz help me

    ReplyDelete
  22. Hi great tutorial, please clarify where do I find the code to download?

    ReplyDelete