Arduino Mega 2560 R3, ICSP Programming and Bootloader Reload using AVRDUDE

Using an off-board programming tool, it’s possible to program the Arduino Mega 2560 directly through the ICSP pins.

I have a Sparkfun Pocket AVR Programmer at my desk, but according to their documentation as of 04.12.2015, the ATmega2560 is unsupported. Pololu has an inexpensive USB AVR Programmer that is up to task.

Software:

Hardware:

ICSP Programming:

  1. Install all software for the Arduino IDE and Mega. Make sure you can program ‘Blink’.
  2. Follow all the installation instructions for the AVR Programmer.
  3. Install AVRDUDE. Sparkfun and Adafruit have tutorials if you’ve never used.
  4. Open the Arduino IDE for software development, and a command window for programming.
  5. Make yourself an Arduino sketch, perhaps fork ‘Blink’ and change the blink times to 5 seconds. Verify…but don’t upload.
  6. The compiled .hex is found in your AppData directory, on my computer it’s here: “C:\Users\samueltoepke\AppData\Local\Temp\buildXXXXXXXX.tmp”. AppData is hidden by default, so make sure to change that setting in “Folder and Search Options -> View -> Advanced Settings -> Show Hidden Files, Folders, and Drives”.
  7. Make sure the Arduino is being powered by a DC source, the AVR Programmer is properly connected to the ICSP connector, and the USB cable is unplugged. Full_Hookup
  8. In the command window, run your version of (make sure to change file and COM port): ($ avrdude -p m2560 -c stk500v2 -P COM14 -b 115200 -F -U flash:w:”C:\Users\samueltoepke\AppData\Local\Temp\build7577322246968947662.tmp\BlinkDiff.cpp.hex”:i).
  9. The end result should look like: 1
  10. Continue developing in the Arduino IDE, and uploading the .hex files using the command window.

Reload Bootloader:

When you’re done with your project, it will be necessary to re-burn the Arduino Bootloader if you want to use the board with just a USB cable again.

You’ll have to find the bootloader .hex. It can be downloaded online, or you can get it from your Arduino IDE install folder. Searching for “stk500boot_v2_mega2560.hex” using Windows Explorer in your install directory “C:\Program Files (x86)\Arduino” should find it. For my version/install the file was in “C:\Program Files (x86)\Arduino\dist\default_package.zip\packages\arduino\hardware\avr\1.6.2\bootloaders\stk500v2\stk500boot_v2_mega2560.hex”.

  1. In the command window, set fuses: ($ avrdude -P COM14 -b 19200 -c stk500v2 -p m2560 -v -e -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m).
  2. Result: 2
  3. In the command window, burn bootloader: (avrdude -P COM14 -b 19200 -c stk500v2 -p m2560 -B 1 -v -e -U flash:w:”C:\Users\samueltoepke\Documents\stk500boot_v2_mega2560.hex”:i -U lock:w:0x0F:m).
  4. Result: 3
  5. Unplug the DC power, unplug the AVR Programmer, hook the USB cable up, restart the Arduino IDE, and you should be able to Verify and Upload code without a problem.

References:

Leave a Reply