Arduino Nano as an AVR ISP – In System Programmer

Today i am writing a little article about using an Arduino Nano as an ISP programmer. Not that there are not enough articles about that topic, but I had to use several sources to get it runnig. Another question you want to ask yourself is why you should need this. Basicly I have four reasons:

  • burning a bootloader to an empty chip
  • replacing the bootloader with a custom one
  • writing the fuses
  • incapability to loose that 0,5Kb of bootloader space

If you don’t want to read me blabbing, just skip to the „Preparing the Programmer“ section.

The Hardware

For my small projects I use these nice little Arduino boards, more specific the Nano or the Pro Mini. I must confesst, that i still have troubles spelling Arduino, but I love these boards for several reasons:

  • They are so cheap (if you order the Pro Mini via ebay from China they are like 2,40€ or even cheaper, the Nano with CH340G is like 2,85€)
  • They usually come with a bootloader
  • They have a linear regulator on board, that allows them to be sourced from up to 12V (use the RAW pin!)
  • They come with the pins unsoldered, what allows you to solder resistors, transistors and stuff directly to the board.
  • It’s a AVR 328P, so you can just use gcc and eclipse, no need to use Arduino Studio

The Nano used to be more expensive, since the FTDI Chip on them is expensive and I don’t have a CH340G yet, but for now I assume it works just fine. Anyhow, for the Pro Mini i use an FTDI breakout board, that I can quickly just slide inside and programm it. This makes projects, that just sit around even cheaper, especially since I got my Pro Minis for 1,99€.

Summing up, nice and cheap hardware with great support.

Preparing the Programmer

You need an AVR 328P with a serial bootloader and a serial to USB converter. A nano offers that on one board, but a USB Serial converter with a Pro Mini works as well. Until i mention anything else, the following steps need to be done on this first Arduino that will become the ISP.

This one is just great, pins in the right order for the Arduino Pro Mini and a jumper for select between 5V and 3,3V

This one is just great, pins in the right order for the Arduino Pro Mini and a jumper for select between 5V and 3,3V

With the right serial USB adapter you can quickly flash your cheap Arduino without soldering with just some pressuer from two fingers

The quick flash grip. In this combination the Mini Pro (16MHz 5V) with FTDI pretty much equals the Nano

Flash the ArduinoISP firmware

You will need the Firmware to turn your first chip into an Arduino ISP, and that just comes with the Arduino software. You want to do this with the Nano disconnected from everything, since I ran in some trouble if the board was connected during flash, meaning that the ISP did not get recognized after flashing.

You will now have to fire up the Arduino software and select the target board, just make sure you use a current version. In this case the Target is the Nano, since target in this case refers to the board, that is going to run the AVRISP software. Select Tools -> Board -> Arduino Nano after that select Tools -> Processor -> ATmega328 and finally select the right serial port under Tools -> Port. Now select File -> Examples -> ArduinoISP what opens up a sketch where you just need to press the arrow button on the top left that states upload, during this the LEDs on the Nano will blink indicating the transfer of data. If everything went fine it should state something like uploading done. If not, check your settings, especialy the port settings and hope you didn’t get a board where the bootloader is missing.

Disable auto reset

Also, the Arduino has an auto reset feature, which you need to disable. This is really important, since the ISP will jump out of the ArduinoISP firmware into it’s bootloader as soon as you try to access it from AVRdude. There are a few ways to achieve this:

  • 120 Ohm resistor between 5V and reset pin (seems not to work for Uno)
  • 10 uF Capacitor between GND and reset pin (seems to work for Uno)
  • disconnect Serial DTR from Reset on chip (not covered here)
  • if you use Serial to USB with Mini Pro, just don’t connect DTR

Since I use an Arduino Nano as an ISP, I soldered a 120 Ohm Resistor across the board and it works for me. From this point on you need to use the reset button on the board to flash a new firmware via the serial bootloader. That is sort of handy, since you won’t overwrite the ISP firmware by accident.

This little 120 Ohm resistor keeps the RESET pin high

This little 120 Ohm resistor keeps the RESET pin high

Wire up Nano to a target

Don’t get fooled: the Nano has an ISP header, which you can not use to connect it to a target. This ISP header is in case you want to use another programmer to flash this device. I fell for this once and of course it didn’t work. Take this table as a reference how to connect.

Description[Programmer]
ArduinoISP (Nano)
[Target]
Arduino Pro Mini
GNDGNDGND
VCCVCCVCC
RESETD10 RST (Reset Pin)
MOSID11 11
MISOD12 12
SCKD13 13

The basic reason the ISP header from the ArduinoISP won’t work is that you would connect RESET to RESET (both input).

Little one and it's more little brother. Six cables and the Nano becomes power supply and ISP for the Pro Mini

Little one and it’s more little brother. Six cables and the Nano becomes power supply and ISP for the Pro Mini

Test Run

You can simply test if everything worked by running AVRdude like so:

avrdude -pm328p -cavrisp -P/dev/tty.usbserial-A9MDD7RJ -b19200

-pm328p defines the target chip (in this case the Mini Pro attached to the Nano)
-cavrisp says that AVRISP is the type of programmer used (since you flashed the Nano with that firmware)
-P/dev/tty.usbserial-A9MDD7RJ is my serial Interface the Nano is connected to under OSX
-b19200 is the baud rate the Nano’s ISP firmware uses to communicate with the host

You should get a reply like that:

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.07s
avrdude: Device signature = 0x1e950f
avrdude: safemode: Fuses OK (E:05, H:DA, L:E2)
avrdude done.  Thank you.

Now you are able to do all that fuses and bootloader stuff AVRdude is capable of or just flash a hex file to the board like this:

avrdude -pm328p -cavrisp -P/dev/tty.usbserial-A9MDD7RJ -b19200 -Uflash:w:SomeFile.hex:a

 

Request fo comments

If it happens that i went too fast at some point, don’t hesitate to post in the comments. I’m glad if I can help someone, who got stuck with that stuff.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.