Go Down

Topic: Bootloader problem - Arduino Mega and Duemilanove (Read 4277 times) previous topic - next topic

drwaseem

Hello,
Well, I am close to killing myself after sending over 10 days and miserably failing at trying to burn a bootloader in a new Atmega328p. Here is what I am doing.
1. I have set up two Arduino boards for this purpose. Using Arduino mega as programmer and Duemilanove as slave (with new Atmega328p). I have followed the instructions given at http://arduino.cc/en/Tutorial/ArduinoISP in letter and spirit.

I get the following

avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

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

Besides that, I have tried every possible way of setting up the atmega on a breadboard with an oscillator and all the relevant circuitry and tried to burn the bootloader with no avail.
Downloaded winavr and tried to do it with command prompt, but failed. I have gone through possibly every post in every forum and youtube videos and what not. Tried putting resistor (or 10uf cap) between ground and reset pin on slave Duemilanove. Nothing happens. Checked the comport, cables and connections a million times over and over but can not burn bootloader.
Used IDE 1.0 at first, it gave a device ID error, now using IDE 0018 and the error message is what I copied up here.
I am new to Arduino and don't want to loose hope in it. Please, any help would be greatly appreciated. Please also let me know how to test if atmega328 is shipped bad to me.

Regards
Waseem

drwaseem

#1
Apr 01, 2012, 10:23 pm Last Edit: Apr 01, 2012, 10:35 pm by drwaseem Reason: 1
Besides, I have also followed instructions given in the following post
http://arduino.cc/forum/index.php/topic,99385.0.html

Setup was same that is, Arduino Mega connected to PC while Duemilanove (with the new Atmega328p) connected with Mega.
Results were frustrating. The IDE 0018 gave following error

avrdude: stk500_getsync(): not in sync: resp=0x0a
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

I have tried this whole and the previous setup with both the new Atmega328p and the one that came with Duemilanove (it is surely working and taking up the sketches) but I can not get the bootloader burned on any atmega328p.

What to do??

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

madworm

And don't kill yourself because of THAT.

But please familiarize yourself with the concept of getting the right tools for the job. Spending somewhere between 10-30$ for a programmer would most likely (*) have saved you from spending 10 days in self-inflicted hell.

(*) If you use windows that may or may not be different.
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

HugoPT

try to disable the autoreset on the arduino you want to program.you must add a 120 resistor from reset pint to 5V.
You should then be able to sucessefuly upload the bootloader then
Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B

drwaseem

Dear Mr. Gammon,
Here are the pics of the setup. Mega being the programmer and Duemilanove being the slave with the Atmega 328p insterted waiting to be bootloaded.

@madworm, yeh, the bootloader literally sucks big time. How can one possibly know what the right tools are for this job besides owning two arduinos?? It is supposed to work rightaway!

@HugoPT, I have already tried that. In the pics attached too, I have a 120ohm resistor connected to +5v and Resest. And here is the output error given by Arduino IDE 0018
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

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

In the pics, I have tried putting the resistor and disabling reset on Duemilanove with and without connecting pin 10 of Mega to reset on Arduino.

Guys, I really need some help here.

Regards


CrossRoads

#6
Apr 02, 2012, 10:32 pm Last Edit: Apr 02, 2012, 10:38 pm by CrossRoads Reason: 1
Have you tried this approach?
See the video  in this thread
http://arduino.cc/forum/index.php/topic,68183.0.html
https://github.com/WestfW/OptiLoader

Mega     Duem
D10       Reset
D11       D11
D12       D12
D13       D13
Gnd       Gnd
+5         +5

Load the Optiloader sketch on the Mega, put a blank part in the Duem.
Reset the Mega, it will read the blank part and put the correct bootloader based on the blank part's signature.


I also have a Duemilanove modified to bootload parts by adding a few pins to X3 next to the FTDI part, and making a little cable to connect them to the ICSP pins.
Took a while to setup the software on IDE -0022, but it does work.

http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html

Nowadays I just use an AVR ISP tho. Nice tool to have.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

If my eyes don't deceive me you appear to have swapped pins 10 and 11. Why did you do that?

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Actually I withdraw that comment. On closer inspection you didn't ... I don't think.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

From this page:

http://arduino.cc/en/Tutorial/ArduinoISP

Quote
On the Arduino Uno, you'll need to connect a 10 uF capacitor between reset and ground (after uploading the ArduinoISP sketch).


You aren't using a Uno to program, but I suspect that disabling reset on the Mega using that method might help.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

CrossRoads

If running the optiloader sketch, disabling reset is not needed.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

Right then. Let me describe what I did to get to this point:

Code: [Select]

$ avrdude -c arduino -p m328p -v -P /dev/tty.usbmodemfd141 -b 19200


         avrdude: Version 5.8cvs, compiled on Jan 15 2010 at 17:27:01
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/CrossPack-AVR-20100115/etc/avrdude.conf"
         User configuration file is "/Users/nick/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbmodemfd141
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done.  Thank you.


You will note that it detected the ATMEGA328P part, and read the fuses. So from here on, it is just formality I think.



First important point: Since we are using a Mega, and programming is done via SPI, we need to use the Mega SPI pins, not the Uno ones.

Code: [Select]

Mega      Duem
D53       Reset (SS)
D51       D11 (MOSI)
D50       D12 (MISO)
D52       D13 (SCK)
Gnd       Gnd
+5         +5


Next, I uploaded the "example" ArduinoISP sketch that shipped with 1.0 of the IDE onto the Mega.

Then, it appeared to work better (ie. at all) if I stuck a 10 uF capacitor between Reset and Gnd on the Mega.

It also appeared to need the Mega to be reset (ie. reset button) before trying anything. Wait a few seconds for the Tx/Rx lights to stop flashing, as the bootloader on the Mega tries to do serial comms.

Then I used avrdude on the command line, after working out which comm port the device was recognized on (in my case, /dev/tty.usbmodemfd141).

Code: [Select]
avrdude -c arduino -p m328p -v -P /dev/tty.usbmodemfd141 -b 19200

The -v just checks that it can communicate with the target device.

If you want to see more, replace -v by -vvvv and then you see stuff like this:

Code: [Select]

         Using Port                    : /dev/tty.usbmodemfd141
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
         AVR Part                      : ATMEGA328P

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

CrossRoads

So you're not running westfw's optiloader then?

See the video here
http://arduino.cc/forum/index.php/topic,68183.0.html
My understanding was that after connecting the 2 systems, pressing reset on the master started the process, and when done it just waited for another reset to start the next bootloading operation.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon


So you're not running westfw's optiloader then?


No, I was just using the supplied ArduinoISP sketch to turn the first Arduino (in this case the Mega) into an ISP programmer. Then you use avrdude in the usual way .
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

drwaseem

@CrossRoads,
I have tried this approach. Let me explain it here in detail so that if I may be guided if there is something wrong with what I am doing.
1. downloaded optiloader .pde and .hex from https://github.com/WestfW/OptiLoader
2. Copied both files in a directory named Optiloader and placed that directory in Libraries folder within Arduino folder.
3. Compiled the sketch and uploaded it to Mega.
4. Connected Duemilanove (having new Atmega328p inserted) with mega exactly as the way you described.
5. press the reset button on mega, the LED connected to D13 of both mega and duemilanove flash multiple times and then turn off.
6. Now connected the Duemilanove(with new Atmega328) with PC. Removed all cables connecting it with mega and tried to upload the sketch to Atmega328. It says, error uploading.
7. When I press reset on Duemilanove, the LED on D13 does not flash meaning, no bootloader was installed.

Currently working on the method shared by Mr. Gammon. Will post the results as soon as I am done with it.
Man, it sucks!! Any ideas?

Regards

Go Up