Modifying the arduino to burn other avr chips

ISP and ICSP are slightly different terms that refer to the same concept In System Programming or In Circuit Serial Programming – and they roughly interchangeable when it comes to Atmel AVR chips, the microcomputer brain at the core of the arduino.

The arduino is designed with a 6-pin ISP header that is there so you can program the chip on the board from an external programmer. In the event that you were to put a fresh new chip into the socket, this header would be a handy thing to have around.

You could use a programmer like the stk500, AVR-ISP, or any of a number of third party devices.

Notice the familiar 6 pin header on the stk500 with the label ISP6PIN:

If you look closely at the stk500 photo, you’ll also notice that pin1 on the header is marked, just like it is on the arduino:

You could connect them up with a six pin ribbon cable like this one:

The red stripe on the side helps when you get confused.  Those of you who connected up floppy drives and hard drives to pc motherboards when you were younger (weren’t we all younger?) may remember your first encounter with ribbon cables and that comforting red stripe.

You just make sure pin 1 connects to pin 1 on both boards and you’re all set to go!  (After you learn the wily ways of AVR Studio or avrdude, of course.)

Hey!   But what if you already have a working arduino?   In that case your chip at the helm has long since sown its wild oats and been initiated in the ways of the arduino bootloader (just like all of mine have always been when they’ve arrived in the mail).  In that case, you already have a completely functional In System Programmer that can program other avr chips!

It sounds so easy doesn’t it?  But yes, you guessed it, there is just one catch. Something is amiss, there is something in this picture that is out of place – can you spot it?

Look closely at the schematic, the ICSP (or ISP) header looks like this:

Following each of the lines in the schematic carefully, you will notice that they are connected as follows:

1. PB4 MISO  (master in, slave out)
2. 5 volts
3. PB5 SCK (serial clock)
4. PB3 MOSI (master out, slave in)
5. RESET
6. Ground

This is all part of the Serial Peripheral Interface Bus, or (SPI), that is built into every AVR chip, the hidden system that does the work to program every functioning arduino.

But wait, what’s all this master/slave business?  It’s a communications term from way back in the dawn of human civilization, somewhat recently deemed inappropriate in LA, which refers to special things that happen between two interconnected devices that would be inappropriate to discuss on a public forum with anything except hand-wavy euphemistic terminology that disguises what’s really going on.

The cool thing about the SPI arrangement though, is that MOSI and MISO always connect to other pins also labeled MOSI and MISO, so there’s no crossing of cables with Ins and Outs getting all switched up and mixed up every which way – MISO always connects to MISO, and MOSI always connects to MOSI.  SCK connects to SCK, and of course 5v is 5v and Ground is Ground.

This leaves us one fly in the ointment.  RESET is serious business when it comes to serial programming, because if both chips were to reset at the same time, well, the whole master/slave situation would get totally out of hand.  So the First SPI Programmers decided that there would be this thing with which one chip could select another, called, yes, creepily – Slave Select or SS.

If you look again at the schematic, you’ll see that our own PB2 SS is blissfully wandering about on its own, completely unconnected to the ISP header.  This is because the arduino was designed so that any AVR MEGAx82 chip you might put into the socket would swiftly fall prey to other, better prepared chips, whose headers have their ISP pin5 connected to their SS pin instead of their RESET pin.

“Aha! ” you say, “the solution is simple!”  We’ll just make a mess and run wires everywhere, then we can take advantage of other unprepared soft-bellied chips, like so:

(Exercise for the reader: notice what pins are connected to the chip?  There’s power, and ground, and hey are those PB2-5, aka digital10-13, aka SS, MOSI, MISO, and SCK?  Just checking!)

And that could be fine, because well, messes have their place, wires are wires, and it is better to get the job done than to wait around for new parts and fancy schmancy programmers to arrive in the mail.  Plus, those chips had it coming, but what if you could do all that and have a nice clean fancy schmancy programmer for no cost whatsoever?  Then you could spend your money on nicely labeled breakout boards like this one from sparkfun:

Well if you want to, here’s how!
(I swear I’ll be less long-winded in this section):

What you want is for your AVR chip to be connected to the header as follows:

1. PB4 MISO (master in, slave out)
2. 5 volts
3. PB5 SCK (serial clock)
4. PB3 MOSI (master out, slave in)
5. PB2 SS
6. Ground

This is going to require cutting two traces, and making four solder connections.

The Arduino Duemilinova has a really nice, handy reset button on the board.  It turns out that this is connected to the ISP header Pin5, and then ISP header Pin5 is thereafter connected to the reset pin on the MEGAx82 (chip pin1).  So if you want that button to still be handy, you’ll want to cut both traces leading from the ISP header Pin5 and bypass it with a wire.

===  The Process… ===

First I tested all the connections with an multimeter to make sure I knew what was connected to what.  A reassuring beep from the multimeter told me that I knew which pins were which and that the leads were in fact connected the way they seemed to be.

And now here’s the scary part, but don’t be squeamish, you are about to become Somebody Who Does Things To Their Board.  If you google cutting traces and read the discussions, you’ll see people have all kinds of opinions about how to do this, and many of those opinions probably have their place.  For this modification however, I had no trouble using an X-Acto style artist’s knife.   I then followed up by testing with a multimeter to make sure I had created an open circuit between the reset button, the ISP pin, and micro’s RESET pin.

Click any picture for a larger image:

Step 1 – Cut the trace between Pin5 and the micro’s RESET

Step 2 – Cut trace between ISP Pin5 and the reset button

Step 2 – solder to reset button:

Step 3 – solder reset button to micro Pin1 RESET:

Step 4 – solder to micro Pin16 SS:

Step 5 – solder SS to ISP Pin5

Congratulations, you are good to go!  Well almost.

There is one, additional, non-invasive thing you must do:

Every time the USB port opens up a new connection to the Duemilinova Arduino, it resets the chip.  This is kind of like the conceptual situation I mentioned before in which both chips getting reset might cause everything to get all higgledy piggledy.  Well it turns out it’s true.

You could cut the reset trace, but then you limit the functionality of your arduino.  Until now, every change we’ve made has only enhanced what your arduino can do, so there’s no sense in getting hasty now.  A small resistor, between your 5v out and reset input on the side of the board will make everything work perfectly.  I used a 120 ohm resistor successfully, but judging by this discussion I wouldn’t go much higher than that.

I have been using the arduino library MegaISP for writing to other chips using this modification, and it has pleased me greatly.

I hope this article is useful to someone, it is my first real article for Open Music Labs!

This entry was posted in arduino, avr, how-to, ISP, modifications, updates. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>