Uploading using programmer success but not running (Solved)

Hi all,

I have created a standalone AtMega2560 and have been able to burn the boot loader via a USBasp and am able to upload a simple blink sketch using the programer, I receive a message saying done, when uploading the sketch but nothing runs. ( The led is on pin 10 so I change that is this code and double and triple cheeked that the LED is on Pin 10 PB4(0C2APCINT4)),

I have tried other sketches but still nothing.

So far I have also tried using a UNO as a Programmer with the same effect, I also tried Nick Gammon AtMega Board Programmer, with Bootloader from the Arduino IDE the AtMega Board Programmer, the verification fails, with output such as

Verification error at address 3E000. Got: 0xFF Expected: 0x0D
Verification error at address 3E001. Got: 0xFF Expected: 0x94
Verification error at address 3E002. Got: 0xFF Expected: 0x89

after programming with the AtMega Board Programmer, i get the expected output in the command line but still no apparent activity after uploading the sketch successfully.

Entered programming mode OK.
Signature = 0x1E 0x98 0x01
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
Lock byte = 0xEF
Clock calibration = 0x98
Bootloader address = 0x3E000
Bootloader length = 7474 bytes.

Any ideas?

Just to add when I try to upload the boot loader from an UNO after running AtMega Board Programmer i get the following error

avrdude: verification error, first mismatch at byte 0x4439
0xff != 0x00
avrdude: verification error; content mismatch

Check out this thread, they had a similar issue, program was loaded but didn't run. They had to change a fuse in order to work properly.

http://forum.arduino.cc/index.php?topic=126160.0

Try this setup taken from the thread.

## Arduino Mega w/ ATmega2560 Testato Mega ISP Version
## -------------------------
mega.menu.cpu.atmega2560T=ATmega2560 (Testato ISP Version)

mega.menu.cpu.atmega2560T.upload.protocol=wiring
mega.menu.cpu.atmega2560T.upload.maximum_size=258048
mega.menu.cpu.atmega2560T.upload.speed=115200

mega.menu.cpu.atmega2560T.bootloader.high_fuses=0xD9
mega.menu.cpu.atmega2560T.bootloader.extended_fuses=0xFD
mega.menu.cpu.atmega2560T.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex

mega.menu.cpu.atmega2560T.build.mcu=atmega2560
mega.menu.cpu.atmega2560T.build.board=AVR_MEGA2560

Thanks for the information.

So from the text I add this to my boards.txt which I done,

Should I be selecting this and using this to burn a boot loader? if so there is no name suffix so it shows up as a blank option in the drop down list for the boards. When I try to burn this i get a huge error :cold_sweat:

avrdude: AVR Part "null" not found.

Valid parts are:
t10 = ATtiny10 [/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf:16673]
t9 = ATtiny9 [/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf:16629]
t5 = ATtiny5 [/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf:16585]
t4 = ATtiny4 [/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf:16541]
ucr2 = 32UC3A0512 [/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf:16520]
....
.... etc

or should it have the same prefix as the standard AtMega2560 prefix

mega.menu.cpu.atmega2560T=ATmega2560 (Testato ISP Version)

i.e

mega2560.name=Arduino Mega 2560 or Mega ADK

making each line

mega2560.menu.cpu.atmega2560T=ATmega2560 (Testato ISP Version) etc

Appreciate your comments

So far I have also tried using a UNO as a Programmer with the same effect, I also tried Nick Gammon AtMega Board Programmer, with Bootloader from the Arduino IDE the AtMega Board Programmer, the verification fails, with output such as

Verification error at address 3E000. Got: 0xFF  Expected: 0x0D

Verification error at address 3E001. Got: 0xFF  Expected: 0x94
Verification error at address 3E002. Got: 0xFF  Expected: 0x89

Getting 0xFF means it didn't program at all. Check your fuses, your clock speed, decoupling capacitors, that sort of thing.

Thanks Nick, When I program with your Atmega Board Programmer I first get the 0xFF errors like you said and then when I use it to program the chip it does this very fast 1-2 seconds and verify is ok.

when I first run the AtMega Programer i get the following fuse settings and verification errors

LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
.

After programming the fuse settings remain the same but the verification settings are gone
Entered programming mode OK.
Signature = 0x1E 0x98 0x01
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
Lock byte = 0xEF
Clock calibration = 0x98
Bootloader address = 0x3E000
Bootloader length = 7474 bytes.

Only when I try to load a sketch nothing happens.

Try HFuse as D9 instead of D8 as I suggested.

High fuse of D8 means it uses the bootloader.

I just uploaded a sketch to my Mega2560 and its fuses were set to:

Atmega chip programmer.
Written by Nick Gammon.
Version 1.21
Compiled on Aug 30 2014 at 14:34:02
Entered programming mode OK.
Signature = 0x1E 0x98 0x01 
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF 
HFuse = 0xD8 
EFuse = 0xFD 
Lock byte = 0xEF 
Clock calibration = 0x5D 
Bootloader address = 0x3E000
Bootloader length = 7474 bytes.

Hi All,

I am a little bit confused what to do next.

Should the high Fuse be set to D8 or D9?

Looking at your output nick the only difference I see is the clock calibration

Clock calibration = 0x98 verus 0x5D

I have attached the schematic for your review.

Thanks

Sorry. For the confusion. If you are uploading with bootloader, hfuse is D8.
If uploading with isp programmer, try D9.

Hi mart

I tried D9 on the high fuse by editing the board for the ATMega2560, i could not get it to work as it was in the other thread.

Upload failed with Arduino as ISP but worked with USBAsp programmer, still not effect after uploading the sketch via the USBAsp.

Got it to work finally, it does seam that the Hfuse setting to D9 works.

Thanks

Glad it worked :slight_smile:

Soler:
Got it to work finally, it does seam that the Hfuse setting to D9 works.

Thanks

After doing D9 it works but it won't upload any new sketches via FTDI. Any idea for this one?

With the issues with the Mega2560 that I have discovered when using it with the USBasp ICSP programmer I thought I would try to make several other people’s lives easier but putting the full facts out there. Feel free to correct me if I have things wrong in the summary below.

This issue with the Mega 2560 and the USBasp programmer connected to the ICSP port has got unfortunately three facets to it which I will go over below.

BACKGROUND
The first is that the Mega 2560 with 256KB is the only AVR micro-controller that I am aware of in common use that exceeds the 128KB program size (flash). Most other micro-controllers are in the program size (flash) range of 8-32KB.

ISSUE 1 – NEW ISSUE CAUSED BY LARGE FLASH SIZE OF MEGA 2560
The first issue relates to the operation of the ICSP port on the Mega2560 (not the ICSP port for the 8U2 or 16U2 micro-controller for USB<->Serial comms). The issue here is that the ICSP protocol uses two functions to set the address:

  1. The Load Program Memory Page (LPMP) which takes a 16 bit address (ie. 0x0000 – 0xFFFF).

  2. The Load Extended Address Byte (LEAB) which deals with addresses that exceed what 1) can handle. This sets the part of the address higher than the 16 bits allowed in LPMP.

For most processors the LEAB is not needed as the address fits within the LPMP range. The address of 0xFFFF corresponds to the 64KB boundary but because this is a WORD address (not BYTE address) the actual memory range LPMP handles is therefore 128KB. A byte is 8bits and a word is 16bits.

TAKEHOME MESSAGE:
The take home message is that the Mega 2560 needs to use the Load Extended Address Byte (LEAB) function to access all of memory correctly. Any programmer using the ICSP interface MUST implement the LEAB function correctly. This will not be an issue for any other AVR micro-controller that has less than 128KB of flash, eeprom etc. Most other micro-controllers do not have more than 128KB of program space (flash).

ISSUE 2 – THOMAS FISCHL FIRMWARE ISSUE
While there are several USBasp programmers made from different companies they largely operate off firmware from Thomas Fischl who looks to be a German chap. The second problem comes to a head with firmware V1.04 (usually dated as being 28 May 2011 version). This firmware purports to support Mega2560 extended address space but has a bug that causes another set of issues.

In summary the issues are:

a) PART A OF ISSUE 2 (HFUSE IS 0xD8)
If the hfuse of Mega2560 is set to 0xD8 then it will be possible to program the second half of the flash address space (corresponds to byte addresses from 0x20000 to 0x3FFFF). The fuse setting for the Mega2560 typically has the bootloader located at word address 0x1F000. This corresponds to byte address 0x3E000. This means the normal fuse setting of hfuse=0xD8 allows the bootloader to be burnt to flash. In fact it will also burn the bootloader at address 0x1E000 as well but it will never get run from there. This burning at 0x1E000 is pointless but is an issue related to not handling the 0x3 part of the address correctly.

b) PART B OF ISSUE 2 (HFUSE IS 0xD9)
The other scenario you get is if the hfuse is set to 0xD9. This will not execute the bootloader but instead immediately executes the users application. When this fuse is set it will be possible to correctly program the lower address space (bottom 128KB) but the top 128KB will just be a copy of the lower address space - the users program will be loaded a second time at an address that will not be used – like the situation with PART A ISSUE 2. The users program will basically be loaded at address 0x00000 and will also be loaded at 0x20000 (start of second 128KB of flash).
A related issue here is that I purchased my USBasp from Jaycar in 2018 and despite being well after the V1.04 firmware creation date in 2011 it still had V1.02 on it. Even though I upgraded it to the latest version (V1.04) the bug I have just documented here as issue 2 then raised its head.

TAKEHOME MESSAGE:
So even if you do the upgrade to USBasp V1.04 from Thomas Fischl you are stuffed if you are wanting to load both the bootloader AND your application into flash – or make a complete copy of flash in the Mega2560. In my case I wanted to make a full backup of the Mega2560 and that was also not possible. The file that is created has had no errors flagged in the process but it will not work if you use it to reload your Mega2560 and you want the bootloader AND your sketch (application) loaded back again.
The command to dump what is in flash should be (from cmd prompt):

avrdude -p m2560 -c usbasp -C -Uflash:r:flashbackup:r

but if written back to flash with hfuse = 0xD8 the bootloader will be there but not your application (sketch):
avrdude -p m2560 -c usbasp -C -Uflash:w:flashbackup:r
You need to download a version of the firmware which properly works with the Mega2560 and this one appears to do just this:

ISSUE 3 – USING AVRDUDE WITH -p wiring HAS TIMEOUT ISSUES
The last issue is that I thought given the Arduino IDE uses the wiring interface to program the sketches into the Arduino, and this works, could I bypass the USBasp programmer and just use the AtMega16U2 USB to Serial chip to do what I want. After all this is how the Arduino IDE uploads my sketches.

The answer is no – well not in terminal mode. When using avrdude to connect to the Mega2560 I ran it from a cmd prompt as follows:
avrdude -p m2560 -c wiring -C -B 19200 -P COM4 -t

With my limited understanding I would have thought this would have worked. Unfortunately reading the fuses was only partially successful and reading flash or eeprom was always unsuccessful:

in avrdude:
avrdude> dump flash 0 300 - FAILS
avrdude> dump eeprom 0 300 – FAILS
avrdude> dump hfuse or dump efuse etc – PARTIALLY SUCCESSFUL

When the -t switch is used with wiring because it talks via the Mega16U2 chip there is a timeout built into the firmware on this chip that largely makes using this method hopeless. It will timeout before the user generally enters too many commands.
You can use to wiring interface to dump the flash out:
avrdude -p m2560 -c wiring -C -B 19200 -P COM4 -Uflash:r:flashbackup.bin:r
because there is no delay waiting for the user to enter the command but unless you know about this timeout preventing -t (interactive terminal mode) from working you are stuffed again.

TAKEHOME MESSAGE:
The wiring interface which is what the Arduino IDE defaults to will work with the Mega2560 but unless you avoid terminal mode your mileage will vary. For the beginner in AVR & Arduino there are limitations which preclude the use of terminal mode as a second option to doing basic things like dumping flash or eeprom when using the USBasp programmer. Your output will show all 0x00’s which is crap. You will also get the occasional stk500_v2 error. When the USBasp programmer is connected instead the avrdude terminal mode there is no timeout issue.

Overall a painful learning experience and one that I hope may help you.

I also believe the errors that Soler had at the start of the post are caused by this rollover effect to the next block of 128KB and avrdude getting back the contents of a different address in flash to what the flash file is processing.

hey guys, can you help me pls, my problem is that my arduino mega is doing ok before add the zip file of thingspeak particle, after i add it my arduino did not run the code that i upload in it, the code was successfuly upload. then when im trying to upload or compile it, in the message box, it says something about the bootloader. can you help me? thank you in advance