Go Down

Topic: Mega 2560 R3, eXtreme Burner and AVR Programmer (Read 19827 times) previous topic - next topic

DaveO

Need some guidance please.

I have an older faulty Mega2560 that I need to replace.

Seems to be a USB problem, as the PC ( XP sp3 ) only sees an "Unknown Device" and I have spent weeks looking for a solution.

I want to work out how to program the old Mega2560 board using an AVR Programmer and ICSP connection.

However, I can not risk damaging or destroying the existing Mega2560, so here is my plan :

Use a new Mega2560 and AVR Programmer. Once I get these working well and reliably, try to re-program the old board. If this does not work, then I can upload my sketch to the new Mega2560 and replace the board.


Purchased a new Mega2560 R3, and an AVR Programmer
http://www.jyetech.com/Products/073/e073.php

and downloaded the latest version of eXtreme Burner 1.3 from
http://extremeelectronics.co.in/software/extreme-burner-avr-1-3-beta-test/

I have made a cable to connect pins :
Code: [Select]

AVR Prog pin 9 - MISO  to  Mega ICSP pin 1
AVR Prog pin 2 - Vcc  to  Mega ICSP pin 2
AVR Prog pin 7 - SCK  to  Mega ICSP pin 3
AVR Prog pin 1 - MOSI  to  Mega ICSP pin 4
AVR Prog pin 5 - RST  to  Mega ICSP pin 5
AVR Prog pin 4 - GND  to  Mega ICSP pin 6


I am a bit confused here, as I don't know if the "Power Target" jumper should be on, and if the Vcc pin should be connected to the Mega2560.

If I leave these off, and I power the Mega using the USB cable, will the fact that it is plugged into the USB somehow prevent the AVR Prog from uploading over ICSP ?


When I connect the new Mega to the PC USB cable, the PC immediately detects the board, installs the driver, and creates Com3.

Next, I connect the AVR Programmer to the Mega2560 with the newly made cable ( tested with m.meter and all connected, no shorts ).

Plug the AVR Prog into USB, and the PC detects and installs the "LibUSB-Win32 Devices" > "USBasp"

Start eXtreme Burner, set the chip to ATmega2560 and open an existing sketch ( Blink ) and "build only" - works fine.

Use the "Read All" option, and retreives data from the Mega2560 board. ( does report errors if either the AVR Prog or Mega is disconnected, so reasonably certain it is communicating with the Mega ).

Here is where the problem started ...

I think, if I understand correctly, using the AVR Prog to upload has erased everything on the chip and uploaded the hex file.

This means that I can no longer use the Arduino IDE to upload to the board with USB ?

Tried to upload Blink, and takes a few minutes and eventually returns :
Code: [Select]
Binary sketch size: 1,718 bytes (of a 258,048 byte maximum) - 0% used
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer


I think that the IDE can definately see the board, because if I unplug the board from the USB cable, it reports :
Code: [Select]
Binary sketch size: 1,718 bytes (of a 258,048 byte maximum) - 0% used
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
processing.app.debug.RunnerException: Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
at processing.app.debug.BasicUploader.uploadUsingPreferences(BasicUploader.java:126)
at processing.app.Sketch.upload(Sketch.java:1649)
at processing.app.Sketch.exportApplet(Sketch.java:1608)
at processing.app.Sketch.exportApplet(Sketch.java:1580)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2408)
at java.lang.Thread.run(Thread.java:619)

   
Next I ( again ) assume that I would need to reload the bootloader to the Mega2560 board ?

Looked around the net, and I can't seem to find any info that agrees - there seem to be multiple bootloaders for the same board ?

I also saw multiple sites with info about the fuses for the Mega2560

If I use eXtreme Burner to read the fuses, I get :
Code: [Select]

Low 0xFF
High 0xD8
Ext. 0x0F
Lock 0xOF


I am not certain that these are correct. Ever since I 'experimented' with some of the fuse values I saw in different related threads, I can upload to the board ( using eXtreme Burner ) but it does not run after I reset the board.

So the problem is 3 part :

1. what should the fuses be set to ?
2. Jumper and pin connections from the AVR to Mega.
3. where is the correct bootloader for the mega2560 R3 board.
4. How to re-enable the USB upload option for the board.
5. is my understanding of the problem correct ?



   
   

CrossRoads

You can install the current bootloader:
Tools: Burn Bootloader
which will set the fuses also, per the settings in boards.txt
This will allow uploading sketches via the USB port if the onboard USB/Serial path is working.
The bootoader is in the IDE directory, look in the /hardware folder I think.

If not, you can use
File: Upload Using Programmer
to load your sketch and not have any bootloader.
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.

DaveO

Hi CrossRoads

Many Thanks for the post.

I found that the USB extension cable fromPC to AVR Prog. was 'dodgy' and was causing a problem.  I have replaced that. ( New USB extension will be returned to store on Tuesday )

I then changed to Arduino Builder ( v 0.8.3 ) and used the AVR Prog to upload the bootloader to the Mega2560, using the USBasp connection.

( ps .. removed external power from the Mega, connected the AVR Prog Vcc wire to the Mega ICSP pin, and added the Jumper on the AVR Prog board to 'Power Target' )

Took about 20 minutes to upload.

This worked, and I am now able to access and upload sketches from the Arduino IDE. Upload Blink and works perfectly.

From this, I assume that the USB chip is OK, and that the fuses are set correctly.

However, if I re-connect the Mega to the AVR prog, and again use Arduino Builder, and upload the Blink sketch, it does not work -- it does not blink like it does if I load the bootloader via AVR Prog. and then Blink from Arduino IDE over USB.

I 'think' the IDE adds the Blink code AFTER the bootloader, whereas the AVR Prog erases the flash before uploading only Blink.

Am I missing something to make the Blink run if there is no bootloader ( assuming that AVR Prog erases the bootloader if programming via ICSP ) ?

I know that the existing (new) Mega2560 will take the upload on USB, but I am wanting to know how to upload working code via ICSP so that I can recover my older damaged board.


ps .. running IDE > Tools > Burn Bootloader  gives an error : avrdude: usbdev_open(): did not find any USB device "usb"

CrossRoads

File:Upload Using Programmer, loads the sketch using the AVR programmer connected to the ICSP pins.

Most bootloaders will make the L LED flash - maybe continuously with three flashes every few seconds, or maybe just a couple flashes after a reset.
I haven't powered up a freshly bootloaded Mega in a while, I don't know what the current bootloader does.
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.

retrolefty


File:Upload Using Programmer, loads the sketch using the AVR programmer connected to the ICSP pins.

Most bootloaders will make the L LED flash - maybe continuously with three flashes every few seconds, or maybe just a couple flashes after a reset.
I haven't powered up a freshly bootloaded Mega in a while, I don't know what the current bootloader does.



I believe the bootloader LED behavior is to continuously blink three flash bursts every so many seconds IF there is no sketch in flash memory to jump to, if there is it jumps to the sketch after just one three second burst. Keep in mind that different bootloaders for different boards over the years can have slightly different LED patterns.

Lefty

DaveO


You can install the current bootloader:
Tools: Burn Bootloader
which will set the fuses also, per the settings in boards.txt


Are you them (silently) saying that the fuses are loaded as part of the bootloader hex file ?

If so, then (my) logic tells me that uploading any sketch (except a bootloader) using Auduino Builder is not going to work, because when it starts uploading it says :

Code: [Select]

avrdude.exe: Device signature = 0x1e8901
avrdude.exe: NOTE: FLASH memory has been specified, an erase cycle will be performed.
avrdude.exe: erasing chip

... and then continues to upload


so my thought is that if the chip is erased, then the fuses are gone as well ?

Is there a way to add / combine the hex file for the fuses with the hex file of the sketch ?

CrossRoads

"Are you them (silently) saying that the fuses are loaded as part of the bootloader hex file ?"
No, I am Explicitly saying the IDE command
File:Burn bootloader
sets the fuses also.

When I do a project, I burn the bootloader as the first step just to get the fuses, even if I plan to use
File:Upload Using Programmer
to then upload my sketch and not have a bootloader.  The fuses will remain as programmed, only the Flash is changed.

I don't use discrete avrdude commands, only
File:Burn  bootloader

followed by
File:Upload Using programmer
or,
I remove the Programmer, connect up to USB/Serial interface and use
FIle:Upload sketch (or whatever happens when the menu icon for uploading is clicked)

There is no hex file for the fuses, just the three lines in boards.txt


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.

DaveO

Tools:Burn  bootloader gives an error :

avrdude: usbdev_open(): did not find any USB device "usb"


CrossRoads

Under Tools: Select programmer
is your programmer selected?
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.

DaveO

Thanks for the pointers.

Changed programmer from
AVRISP mkII
to
USBavr

Displays :.. Burning Bootloader to I/O Board (this may take a minute)...

runs for around 1 hour and then error :

avrdude: verification error, first mismatch at byte 0x1e000
         0xff != 0x0d
avrdude: verification error; content mismatch

I am using Arduino IDE 1.5.2


CrossRoads

Does the sketch seem to run anyway after the verification error?
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.

DaveO

That was only the bootloader.

Once that is done ( and failed verification ) I am able to connect from IDE on USB and upload blink.

However, if I load Blink to ICSP with "Upload using programmer" then it does not run - the LED is permanently lit, and I can not access from IDE over USB again.
Just get the timeout error.
Code: [Select]
avrdude: stk500v2_ReceiveMessage(): timeout

Need to reload the bootloader again I think.

Strange that I can not load Blink over ICSP either with IDE or eXtreme Burner or Arduino Builder. Would that point to some problem with the fuses, or with avrdude, as I think the IDE and Arduino Builder both use it. Not certain about eXtreme Burner.

CrossRoads

I don't know.  My bootloading experience is with Atmel AVR ISP MKii, so I don't normally see these kinds of problems.
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.

DaveO

OK. Here's a completely different look at the problem.

The ICSP upload of the hex of the bootloader works, but the hex of Blink does not.

Assuming that the fuse settings may be in the hex file, what's the possibility that the hex file that I have of the Blink sketch ( made with Arduino Builder ) may be faulty, or contain invalid values for something board specific ?

Does anyone have a hex file of the standard IDE sketch 'blink' that I can test uploading to ICSP ?

CrossRoads

Have you tried just opening the Blink sketch in the IDE and programming it using
File: Upload Using Programmer?
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.

Go Up