ArduinoISP on the Due

There may not be a lot of practical value in running ArduinoISP on an Aruino Due. If you have a Due, it is very likely you have at least one classic Arduino at hand for which running ArduinoISP is well known and documented. On the other hand, ArduinoISP is a standard Arduino sample so I find that it should work on any Arduino. Well, it was good fun to make it work…

Due programming bootloader into a Leonardo

Due programming bootloader into a Leonardo

I found an opportunity to start with this when I wanted to upgrade the firmware of my Leonardo

Since Arduino 1.0.3, there is an improved boot loader for Leonardo that is a real must have: upon power-on reset, it jumps immediately to your sketch instead of awaiting programmer commands for some seconds.

Just for the sake of it I decided use my Due for this task.

Due programming an attiny85

Due programming an attiny85

Later on, I tried to program an attiny85. This required some extra measures. The Due’s SPI runs too fast for these targets so I had to use software SPI to slow the Due down.

Wiring, 5V, 3V3…

First thing to take care of was to make sure not to fry the Due which is not 5V tolerant. Connecting it to the ISP port of the Leonardo powered with 5V would probably damage the Due: the Leonardo would drive the MISO signal to 5V. I took a very simple approach: I powered the Leonardo with 3.3V. See red jumper wire between the Due’s 3V3 (don’t accidentally use the adjacent 5V pin) pin and the Leo’s 5V pin.

As usual, my photo’s are lousy, but these are the connections:

Due     | Target (Leonardo, attiny85...)
 MISO   |  MISO
 SCK    |  SCK
 MOSI   |  MOSI
 GND    |  GND
 3.3V   |  Vcc (labeled 5V, on the Leonardo)
 Dig 10 |  RESET

It should be warned not to connect the 5V (!) power pin from the Due’s SPI header to the corresponding pin on the Leonardo (using a flat cable would do this). Like most people on the forum I expected this pin to carry 3V3, and first I was tempted to use it to power the Leonardo. Well it has 5V. OK, trap avoided.

Also when this wiring is in place, don’t connect the Leonardo’s USB cable !

In general, don’t power the target at 5V when doing this.

Get a “Due – ready” version of ArduinoISP


The version of ArduinoISP that comes with the ide is a bit outdated. It does not even compile for the Due because the SPI functionality is implemented using AVR specific SPI registers.


I keep a version here that works on the Due without need for further tweaking, nor patches in the core.

I plan to write more about its details in a later post. It has some options you can configure and it has a few new fixes.

Also for other Arduino’s, this version works out of the box, with a reasonable default configuration. Therefore I think it is a candidate for inclusion in the IDE.  We’ll see…

Edit November 2015: Since Arduino 1.6.6, these modifications are integrated in the IDE.

I wish to thank Sylvan Butler, whose SPI bitbang implementation I started from.

Try it out.

Compile and upload the sketch to your Due. Once that is done it is ready to do ISP. Use the native USB port (see photo).

From this point on, when it comes to programming a target, it makes more sense to use arduino 1.0.x. This is OK, the IDE does not care your ArduinoISP programmer is actually a Due.

Windows users have one more thing to take care of: the ide must be instructed to use “arduino” as programmer instead of “stk500v1”. It is explained here (go to point 7), but looking back on it, I find it more easy to just go into the arduino-1.0.x\hardware\arduino\programmers.txt and change the entry:
   arduinoisp.protocol=stk500v1
into:
arduinoisp.protocol=arduino

That is it. I tested burning the bootloader into my Leonardo using arduino 1.0.3 on linux (Ubuntu 12.04.2 LTS) and on Windows 7 SP1 64bit. I also burned a bootloader into a 328p clocked with16MHz.

It was also possible to burn some led blinking firmwares into an attiny85 clocked@1MHz, internal oscillator.

Advertisements

12 thoughts on “ArduinoISP on the Due

  1. Błażej

    Hi
    I’ve used your solution but I have a problem with burnig a bootloader onto my atmega328p-pu.
    I’ve done everything as You said, the problem starts when i try to burn a bootloader, the arduino isp sketch seems to work though. I’ve tried to use avrdude directly – here’s response for my command:
    avrdude -C “..\etc\avrdude.conf” -p atmega328p -b19200 -P COM7 -c arduino -F
    avrdude: AVR device initialized and ready to accept instructions
    Reading | ################################################## | 100% 0.04s
    avrdude: Device signature = 0xffffff
    avrdude: Yikes! Invalid device signature.
    avrdude: Expected signature for ATMEGA328P is 1E 95 0F
    avrdude: safemode: Fuses OK
    avrdude done. Thank you.

    When used without -F it shows same results. I’ve digged a lot and i didn’t find a suitable solution. I wonder if it is not something DUE specific and if You could advice what measures can be taken to make it work. I say up front that I have no other Arduino to use as an ISP, this is my first xD

    Reply
    1. petervho Post author

      Apparently serial communication is working, but the ISP is not.
      Usually this is bad wiring or not using a cristal with an mcu that has fuses set for use with a crystal. (though in this case, the setup with the due is much less mainstream of course).

      Don’t use -F, ISP is not working it makes no sense ignoring the signature mismatch.

      Can you post a picture, so I can see the setup?

      Reply
  2. Błażej

    As it appears this setting works, but rarely. I tried about 300 times and it worked 5-6 times.
    I’ve got log from succesful (?) burning but I can’t load program into the chip anyway.

    avrdude: AVR device initialized and ready to accept instructions
    Reading | ################################################## | 100% 0.04s
    avrdude: Device signature = 0x1e950f
    avrdude: safemode read 1, lfuse value: 62
    avrdude: safemode read 2, lfuse value: 62
    avrdude: safemode read 3, lfuse value: 62
    avrdude: safemode: lfuse reads as 62
    avrdude: safemode read 1, hfuse value: d9
    avrdude: safemode read 2, hfuse value: d9
    avrdude: safemode read 3, hfuse value: d9
    avrdude: safemode: hfuse reads as D9
    avrdude: safemode read 1, efuse value: 7
    avrdude: safemode read 2, efuse value: 7
    avrdude: safemode read 3, efuse value: 7
    avrdude: safemode: efuse reads as 7
    [above x2]
    avrdude: safemode: Fuses OK

    Indeed I propably messed something with wireing so i add photos of my setup:

    P.S. Thanks for such a quick replay. It is very reassuring for a newbie to find out that people are willing to help 🙂

    Reply
    1. petervho Post author

      Good that it worked at least once so we know the fuse settings. Low fuse reads 0x62 (probably a new chip?) this means the internal 8MHz clock is used. So you don’t need the cristal nor the caps. Try with XTAL1 and XTAL2 left unconnected, does that make a difference?

      If you want to mount the cristal and caps again (cause you managed to change the fuses), put them directly in the holes next to pins XTAL1/2, without wires That works more reliably.

      You have no 100nF decoupling caps between vcc and ground. I always mount these. Put them (or at least one) as close to the chip as possible.

      Reply
      1. Błażej

        I’ve tried all options above but none work :/
        I’ll remake the setup once more with new parts when I’ll find time, maybe this will work.
        Thanks for advice 🙂

  3. mike

    [QUOTE] From this point on, when it comes to programming a target, it makes more sense to use arduino 1.0.x. This is OK, the IDE does not care your ArduinoISP programmer is actually a Due.

    Why not stay in 1.5.6? (BTW This is a very helpful write-up)

    Reply
    1. petervho Post author

      At the time I wrote that, 1.5.x was still in beta. E.g. support for attiny did not yet work so I had to use 1.0.x to work with attiny targets. Actually right now, 1.5.x is still in beta, maybe in mean time attiny support works again, I did not follow up on that.

      Reply
  4. Robin

    [SOLVED]

    Hello,
    thanks for your work, but it does not work for me. 😦
    I’m trying to flash a bootloader to an Arduino UNO with my Arduino DUE. (PC = Win 7)

    What I did:
    1.) Flashed your ArduinoISP.ino an closed the IDE
    2.) Removed USB-Cable
    3.) Set-Up the wiring
    UNO DUE
    [1][2] [1][ ]
    [3][4] [3][4]
    [5][6] [ ][6]
    wire 5 goes to PIN 10 on the A. DUE
    wire 2 goes to 3.3V on the A. DUE
    4.) Plugged in the Arduino DUE (native port) to the PC
    5.) Downloaded the Arduino IDE 1.0.3
    6.) changed the protocol for arduinoISP
    7.) opened the 1.0.3 version of the IDE
    8.) selected Arduino UNO under tools/board
    9.) selected the right COM
    10.) selected Arduino as ISP as Programmer
    11.) hit tools/burn bootloader

    I just did it again to write what I did -> successful! YEAH! thank you very much!!! 😀

    (I didn’t wired it i just hint burn bootloader several times..!)

    Gratefully,
    RoJaIT

    Reply
  5. Arvind Upadhyay

    hello sir ,
    i am trying to load boot loader in atmega328-pu by arduino leonardo i change setting according to your post ,but i am getting error : ” Error while burning bootloader
    avrdude: yikes ! Invalid device signature .
    Double check connection and try again ,or use -F to override “.
    i am using arduino 1.0.5 ide ,and i also change avrdude.conf file , i changed the signature of device isted of 0x1e 0x95 0x0F to 0x1e 0x95 0x14 .
    Can you please help me. my email id is arv747@gmail.com

    Reply
  6. Pingback: ArduinoISP reliability and portability improvements. | PeterVH

  7. Abhishek

    Hi Peter,

    I have been trying to bootload an Atmega328p from an Arduino Due for the last couple of days with no luck. I followed the tutorial on arduino.cc page here(https://www.arduino.cc/en/Tutorial/ArduinoISP).

    I want to use the atmega with its internal clock(8 Mhz) and so I wired up the circuit as shown here(https://www.arduino.cc/en/uploads/Tutorial/SimpleBreadboardAVR.png).

    I uploaded the ArduinoISP firmware on this page to the DUE using the programing port.
    Then I switched to the native usb port. Then i made all the connections as in the image above. I have also connected the reset pin on the atmega to the 3.3V through 1Kohm resistor.

    The issue is the DUE seems to be shutting off as soon as I connect either 3.3V or 5V pin from the DUE to the atmega.
    The ON led goes out and when i tried to burn the bootloader I got this message
    “avrdude: ser_open(): can’t open device “/dev/ttyACM0″: No such file or directory”

    It seems you had success with chip clocked at 16Mhz. What am I doing wrong? Any suggestions?

    Thanks,
    Abhishek

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s