Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post







MegaISP has supplanted most of the functionality of Programmer2.










This programmer will turn an Arduino into an AVR ISP programmer. It is pin compatible with avrusb500 which implements the newer and saner stk500v2 protocol and will eventually be supported by the Arduino IDE, but until then this one exists to work with the older protocol. Perhaps arduino-0009 will support the new protocol.

Primary Function

You can connect this to your Arduino IDE and connect to the ISP port of your target processor. When you 'upload to target' from the IDE the programmer will flash the program into the target and restart it. You do not need to press reset and there is no timeout delay after flashing. Your sketch will run immediately.

Why Would You Want That?

  • The target might not have a serial port.
  • The target might be a raw chip that is not yet programmed to be an Arduino.
  • The target might have a non-standard clock rate. (USB people use multiples of 3MHz.)
  • The target might not have a reset button, it might be in a physically awkward place, or you could be really lazy and tired of timing the "when to click the target" during the upload to match the sketch size and host computer speed to the bootloader timeout.
  • Breadboarding is trivial if you fuse your processors to use the internal clock. No crystals. Just power, ground, and a resistor tying reset high. (The timing functions in the wiring libraries will be off if you do not have a version fixed for variable clock rates.)

Secondary Functions

If your programmer is a 168 you have room for secondary functions, these are mostly just leftovers from development but some are useful. You access these by connecting to the serial port of the programmer and typing two letter commands, all of which begin with an asterisk.

  • *A - write Arduino style fuses and lock bits to the device. crystal, 1x clock div, 1k or 2k bootloader (mega8, mega168), bootloader unwriteable from app
  • *a - write an Arduino bootloader (you must also do a *A to initialize a virgin chip)
  • *r - remove bootloader (boot directly to sketch)
  • *u - display fuses and lock bits
  • *s - display device signature
  • *e - erase device
  • *f - dump flash
  • *E - dump eeprom
  • *b - write a short test pattern into the flash
  • *B - write a short test pattern into the eeprom
  • Button1 - this runs a standalone programmer mode that erases the target, fuses it in the style of an arduino, and loads a serial bootloader.

Building

Look at the UTILITIES and LCD preprocessor symbols. Turn these off to fit in an atmega8.

Hardware

You will need to make an ISP cable appropriate to your target devices. On the programmer end you must use the following pins or change the definitions:

LEDs for blinking lights, tie to +5 with a resistor.

  • digital5:On This LED lights when the program is running.
  • digital6:Run1 Run1 and Run2 toggle back and forth is data transfers.
  • digital7:Run2
  • digital8:Good Lights at the end of successful run.
  • digital9:Bad Lights at the end of failed run.

These 4 signals go into the ISP connector along with ground and possibly power.

  • digital10:ResetTarget Pull this low to reset the target and prepare for programming.
  • digital11:MOSI Master Out/Slave In
  • digital12:MISO
  • digital13:SCK Serial clock to target.

I put a tiny 9600 baud serial LCD on to show debugging information. There isn't anything useful on it in this set of code, you don't need it. It breaks the protocol because software serial takes too much cpu time.

  • digital18:SerialDebug

You probably don't need these, but I didn't have a hardware reset switch on my tester...

  • digital16:SoftReset You don't need this if you have a hardware reset button.
  • digital17:ForceReset Tied to the programmer's own reset pin to force a reset.

Notes about power

You may or may not want to connect the power line in the ISP. This is complicated. The easiest thing to do is to connect the power line in the ISP, then don't power the target board. This way you will supply the target board from your programmer. You can't do this if the target runs at a different voltage or draws too much current. (This is the method I use.)

Second easiest, you can not connect the power. This is only appropriate if both boards run at the same voltage, but perhaps the target would need too much power to be supplied by your programmer.

If your target runs at an incompatible voltage then you will need to add a level translation circuit of some sort and power each board independently. Since you have both high voltages present, you might get clever with a CMOS switch like a 74HC126N or two.

Source Code

The source code is found in https://playground.arduino.cc/uploads/Code/programmer2.txt and is built like any other sketch.