Pages: [1] 2 3   Go Down
Author Topic: Guide: How to use an Arduino as an In System Programmer (ISP)  (Read 14487 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently bought the "Graphic LCD Serial Backpack" from Sparkfun (http://www.sparkfun.com/products/9352). When reading the comments for the product. I discovered that a user named "SummoningDark", had made a new improved firmware. A lot of people asked Sparkfun to change the official firmware with the new one, so i decided to check it out. The problem were that I do not own a programmer, so at first I thought that I had to buy one. But after some googling I found out that the Arduino could actually be used as an In System Programmer (ISP).
After a lot of work I finally got it working and it has really improved the perfomance of the screen. The speed is much higher (SummoningDark says 10 times) and there are no more bugs (with the old firmware the screen would suddenly write the text or a line a odd place).

I will now try to explain as best as I can, how to upload the new firmware.
NB: You can also use this guide if you need a different bootloader or another hex file on any AVR. This is just meant as an example.

The following DO NOT work with the Arduino Uno, for more information visit: http://arduino.cc/en/Tutorial/ArduinoISP

1) Start up the Arduino IDE (http://arduino.cc/en/Main/Software)
2) Go to File>Exampels>ArduinoISP and upload the software onto your Arduino - if your .hex file is more than 255bytes, you should use the newest version found on this page: http://code.google.com/p/mega-isp/issues/detail?id=14&can=1 (Version dev04b is confirmed to work)
3) Now you have to install AVRDude. I recommend downloading CrossPack (http://www.obdev.at/products/crosspack/index.html) for Max OX and WinAVR (http://winavr.sourceforge.net/) for Windows as it includes all you will need. Including an AVR compiler and AVRDude.
4) Download the program your want to upload. In my case it is the new firmware for the Serial Backpack (http://serialglcd.sourceforge.net/)
5) Compile the program to make a hex file, this can be done by typing "make all"  in a terminal while inside the folder (use "cd" and then the path to the folder - see step 11 for help)
You might have to change some setting for it to work. If there is already an hex file (as in my example) you can just skip this step
6) Now connect the Arduino to the device you want to program. The pin used by the Arduino are as follows:
  • 10: slave reset
  • 11: MOSI
  • 12: MISO
  • 13: SCK
You have to connect these pins including VCC (5V with the Serial BackPack) and GND to the ISP header on your device like so:


The orientation of the ISP header on the backpack is like so:


If you are programming an AVR directly or an Arduino board. See this page for information: http://arduino.cc/en/Tutorial/ArduinoISP

You might also want to connect three LED's (with resistors) on the following pins:
  • 9: Heartbeat - shows the programmer is running
  • 8: Error - Lights up if something goes wrong (use red if that makes sense)
  • 7: Programming - In communication with the slave
7) The next thing you have to do is to connect a 120 ohm resistor (I use a 100 ohm and two 10 ohm resistors) between the 5V and reset headers on the Arduino to disable auto reset on serial connection (http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection) - some people do not need this small hack, so if you have problems to get it working, try without the 120 ohm resistor
8 ) Start up a terminal program. On a Mac simply find the terminal app in the programs folder. If you are using Windows open "run" and type "cmd". Your should now have a terminal window open
9) Now you have to figure out what port your Arduino is using. On a Mac simply type "ls -l /dev/cu.*" in the terminal and all your serial ports should pop up. If you are using Windows open Device Manager>ports and find your Arduino's COM-port. My port is: "/dev/cu.usbserial-A700dX8R", so I will use it in the following example
10) Write the following command in the terminal:
avrdude -p m168 -P /dev/cu.usbserial-A700dX8R -c avrisp -b 19200

"/dev/cu.usbserial-A700dX8R" should be replaced by your port. If your Arduino is on COM port 1, you should write "com1" instead. "m168" means that the target is a ATmega168 see this link for other aliases: http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions

The teminal will print out something like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9406

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Where 0x1e9406 is atmega168 device signature (look in avrdude.conf for other signatures)

11) If everything worked well it is now time for programming your device. The first thing you have to do is go inside the folder where your hex file is located. In my case I just copied the folder "trunk" to the main directory in the harddisk. Your should then use the following command:
cd /trunk

12) Next step is almost the same as 10), but this time you should add -U flash:w:filename to the command. Where "filename" should be replaced with the name of your hex file. In my case the name is "main.hex" so the command should look like this:
avrdude -p m168 -P /dev/cu.usbserial-A700dX8R -c avrisp -b 19200 -U flash:w:main.hex

The terminal will then print something like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (11210 bytes):

Writing | ################################################## | 100% 14.03s

avrdude: 11210 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex auto detected as Intel Hex
avrdude: input file main.hex contains 11210 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 12.89s

avrdude: verifying ...
avrdude: 11210 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


You should now - hopefully - have a new firmware on your device smiley
Hope this will be a help to some, because it really took me a long time figuring all this out.
- Lauszus




« Last Edit: August 03, 2011, 02:11:53 pm by Lauszus » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13668
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks,

no need for it yet but very valuable (please consider posting it on the playground too)

Rob
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not sure how to do that, do I just add it to this post: http://www.arduino.cc/playground/Code/MegaISP?
- Lauszus
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13668
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


could be ok, but a separate article might be prefered, for you to decide ... smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The loginform does not work (http://arduino.cc/playground/Main/LoginForm) or am i just doing it wrong?
- Lauszus
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13668
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


heard that before on the forum, you might need to register separately.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have now registered a new profile, but I still can not make a new page, or figure out how to do so.
I will just add it to http://www.arduino.cc/playground/Code/MegaISP then smiley
- Lauszus
« Last Edit: June 28, 2011, 08:17:58 pm by Lauszus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Lauszus.

With my AVR ISP MkII busted and my FABISP having driver issues, this would work til I get a new AVR ISP.

I made my own version of the GLCD board for a different GLCD. I got the boards but have yet to populate them. I will try the SummoningDark firmware when its up and running.

Roy
Logged

Panucatt Devices

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had hell of a time getting the programmer to work. The ArduinoISP example in Arduino-0022 does not allow more than 255bytes to be uploaded. To solve that you need to use ArduinoISP-dev04b (found at the MegaISP issues page.

Additionally, my Diecimilla mounted Atmega328 refused to act as an ISP with the reset-resistor in place. Removed the resistor and all was golden.


Moderator Edit: Corrected link.
« Last Edit: July 26, 2011, 02:24:09 pm by Coding Badly » Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

#regomodo
Thanks for your respons, I have now updated the guide smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello.
I have to programming a ATmega8 in my own board. I followed the described procedure, but it doesn't work.
avrdude return:
"avrdude: stk500_getsync(): not in sync: resp=0x00"
I tried put 120 ohm resistor VCC to reset: the same result.

Enrico.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you connected everything correctly?
I had problems with the new Arduino ISP code in the Arduino IDE ver. 1, but the one in ver. 0.22 and 0.23 worked just fine smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for replay.

Now I explain my steps:
- I am using Arduino Mega 2560;
- Arduino software 0.22;
- upload sketch 'ArduinoISP';
- connect a ATmega8 with breadboard (for test) to Arduino with single wire for: reset (pin 10 Arduino, pin 1 ATmega8), MOSI (pin 11 Arduino, pin 17 ATmega8), MISO (pin 12 Arduino, pin 18 ATmega smiley-cool, SCK (pin 13 Arduino, pin 19 ATmega8), also connect VCC and GND;
- put 120 ohm resistor between VCC and reset Arduino;
- in console mode I digit: 'avrdude -p m8 -P com5 -c avrisp -b 19200';
- result: avrdude: stk500_getsync(): not in sync: resp=0x00.

What do I worng?

Many thanks for your support.

Enrico.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I looks like that you havn't disabled auto reset properly smiley
Try with a 110 ohm resistor instead. You could also cut the trace labeled "RESET-EN", see http://arduino.cc/en/Main/ArduinoBoardMega2560 at the "Automatic (Software) Reset section".

Regards
Lauszus
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried your indications.

With 110 ohm resistor:
avrdude.exe: stk500_getsync(): not in sync: resp=0x00

Then I cut the trace labeled "RESET-EN", without resistor (first time):
avrdude.exe: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude.exe: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x51


With cutted, without resistor (others times):
avrdude.exe: stk500_getsync(): not in sync: resp=0x00
avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x51


Bye.
Enrico.
Logged

Pages: [1] 2 3   Go Up
Jump to: