Loading...
Pages: 1 [2]   Go Down
Author Topic: Mega 2560 R3, eXtreme Burner and AVR Programmer  (Read 760 times)
0 Members and 1 Guest are viewing this topic.
South Africa
Offline Offline
Sr. Member
****
Karma: 0
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks CrossRoads

I have just done that, and set the Tools > Programmer to 'usbasp'

I did see lights flashing on the AVR Programmer.

Result on the Mega2560 is the same - LED remains on.

From this test, does it sound like something in a config file relating to the 'usbasp' programmer ?

the file : arduino-1.5.2\hardware\arduino\avr\programmers.txt contains :
Code:
usbasp.name=USBasp
usbasp.communication=usb
usbasp.protocol=usbasp
usbasp.program.protocol=usbasp
usbasp.program.tool=avrdude
usbasp.program.extra_params=-Pusb
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 246
Posts: 16526
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't realize you were using arduino-1.5.2.
I was going under the assumption that you had IDE 1.0.3 or 1.0.4
I have not used 1.5.x for anything yet.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

South Africa
Offline Offline
Sr. Member
****
Karma: 0
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks CrossRoads

I have great progress / success, but not certain that it is correct, and don't know how to check it.

Did a search on the verification error that I was seeing after upload and verification of the bootloader :
Code:
avrdude: verification error, first mismatch at byte 0x1e000
         0xff != 0x0d

and found this page :
http://arduino.cc/forum/index.php?topic=126667.0

In the third post ( reply # 2 ) Andre_1949 mentions using different fuses.

Changed my avrdude batch file to use the fuses mentioned in the above linked post, to:
Code:
cd\
cd\ArduinoBuilder\code\Blink
avrdude -v -p atmega2560 -c usbasp -U lfuse:w:0xc2:m -U hfuse:w:0x99:m  -U efuse:w:0xff:m -U lock:w:0x3f:m -U flash:w:Blink.hex

and it uploads and works - LED flashes as expected.


I think that avrdude, as used by the Arduino IDE for 'Upload using Programmer', first reads the fuses, erases the chip, writes the hex file, and then writes the fuses back again. So if the fuses were incorrect before the upload, they will still be incorrect after the upload.

I think that I have confirmed this as follows :

This does not affect an upload of the Bootloader hex file using avrdude from the command line, as the fuses are contained in the hex file.

Any other command line upload fails because I was writing the wrong fuse values, as in :
Code:
avrdude -v -p atmega2560 -c USBasp -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m  -U efuse:w:0xFD:m -U lock:w:0x0F:m -U flash:w:Blink.hex

Arduino IDE upload over USB was fine, because it utilised the bootloader and does not affect the fuses ( fuses that were in the bootloader hex file ).

Arduino IDE 'Upload using Programmer' fails, because the wrong fuses are being read from, and re-written to the board.

Also, after uploading from command line ( and changing the fuses, I can now upload from IDE 'using Programmer' and that also now works ( because it is now reading valid fuses, and re-writing those same valid fuses back at the end of the process ).

So the question now stands : am I using the correct fuse settings for the Mega 2560 R3 board ?

« Last Edit: March 30, 2013, 08:42:37 am by DaveO » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 246
Posts: 16526
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have the fuses that are in the boards.txt file, you have the correct fuses.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

South Africa
Offline Offline
Sr. Member
****
Karma: 0
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well that's the bit I just can't understand.

The boards.txt file shows :
Code:
mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F

but those did not work. I was banging my head against a brick wall trying to find the cause of the problem : suspect USB cable, usbavr drivers, pin settings, hex file creator, bootloader, AVR Programmer board, etc, etc.

And all the time, I was assuming that the fuse settings used in avrdude were correct.

The upload ( or more specifically the running of the uploaded sketch ) only worked using :
-U hfuse:w:0x99:m  -U efuse:w:0xff:m -U lock:w:0x3f:m

Now I just need to figure out if these settings will damage the board in any way.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 246
Posts: 16526
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Run those settings thru a fuse calculator, see what they do for you:

http://www.gammon.com.au/forum/?id=11653
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

South Africa
Offline Offline
Sr. Member
****
Karma: 0
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi CrossRoads

Totally SOLVED !!

And my sincere thanks for your input and very valuable comments and contribution.

I posted on av AVR related forum, about the different fuses - the Mega2560 ones that everyone says should work, and the very different ones that I found in a single post ( that did work ).

Part of the reply that I got was :
Quote
The differences between the two sets of fuses are:
- The first one assumes there is an external clock source in form of a crystal on your board, the second uses the internal RC oscillator for clocking the AVR.
- The first one sets the AVR to start executing a so called bootloader (a program stored in a special part of the AVR, that in turn will communicate over some arbitrary media and program the application proper into the rest of the flash). The second one does not have this bootloader set.
-The second one had disable "brown-out detection", a way for the AVR to detect low voltage conditions and to do a reset if one has occurred.

I also received a link to http://www.frank-zhao.com/fusecalc

I applied the fuses that the Arduino forum experts said should be used :
-U lfuse:w:0xFF:m
-U hfuse:w:0xD8:m
-U efuse:w:0xFD:m
-U lock:w:0x0F:m

I then looked for the bootloader that was mentioned.

Found it in the Lockbit section :
-- Boot Loader Protection Mode 3 : LPM and SPM prohibited in Boot Loader Section.

not certain exactly what that means, but since I an using avrdude to erase the chip and then upload the hex file, I assumed that the bootloader ( or protection of the bootloader section ) is not required, and changed it to :
-- Boot Loader Protection Mode 1 : No Lock on LPM and SPM in Boot Loader Section.

This changed the lock fuse to:
-U lock:w:0xFF:m

Used AVRdude to upload the hex file with these fuses via the AVR Programmer to the ICSP pins, and working perfectly.

I am so pleased to have learnt something ( with help, of course ) that I thought I would never understand.

Thanks again for your input - you certainly helped steer me in the right direction.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 246
Posts: 16526
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you got it worked out.

Here's the details of the bits from the data sheet.  More reading is required to interpret the bits for making changes.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

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