Issue: AVRDude upload to ATmega2560

Hi all,

I have searched multiple forums and guides for the past week but can't find a fix for my problem. Any suggestions would be much appreciated before I have lost all my hair! Sorry for long post but wanted to give what I thought may be useful info... Appreciate your thoughts and thanks for your time.

I recently purchased a Multiwii Pro flight controller with ATmega2560 micro controller. I am running Arduino 1.6.0 on Mac OS X 10.10.2.
I am new to Arduino and so initially I uploaded the basic "Blink" sketch to flash the on board LED. I then modified to turn off LED and re-uploaded. This was working fine and I could connect the board via USB and reprogram multiple times without any issue and see the light on or off.

I'm not sure what happened, but now I can only upload code to my board once upon initial connection (doesn't matter how long it's been connected for so long as I haven't accessed the chip since reconnect). Successful code upload Arduino IDE AVRDude output:

System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/InitialD/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbserial-A502FUY2
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Wiring
         Description     : Wiring
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9801
avrdude: reading input file "/var/folders/p6/kxthnfnd2ps6d_sm8bdzjsxr0000gn/T/build6895625350857975266.tmp/sketch_feb28a.cpp.hex"
avrdude: writing flash (1560 bytes):

Writing | ################################################## | 100% 0.44s

avrdude: 1560 bytes of flash written
avrdude: verifying flash memory against /var/folders/p6/kxthnfnd2ps6d_sm8bdzjsxr0000gn/T/build6895625350857975266.tmp/sketch_feb28a.cpp.hex:
avrdude: load data flash data from input file /var/folders/p6/kxthnfnd2ps6d_sm8bdzjsxr0000gn/T/build6895625350857975266.tmp/sketch_feb28a.cpp.hex:
avrdude: input file /var/folders/p6/kxthnfnd2ps6d_sm8bdzjsxr0000gn/T/build6895625350857975266.tmp/sketch_feb28a.cpp.hex contains 1560 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.39s

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

avrdude done.  Thank you.

When I try and upload a second sketch, I get the following timeout error:

 System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/InitialD/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbserial-A502FUY2
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout

I have tried pressing the reset button whilst the Arduino is timing out but doesn't seem to help.
I have run AVRDude from the terminal so I can check exactly which instructions I am sending.

Could it be something to do with the onboard reset/memory lock? Checked my fuse settings against the ATmega 2560 data sheet and the Arduino boards.txt (and other users)

Me ATmega2560 Default boards.txt
LFuse: 0xFF 0xFF 0xFF
HFuse:0xD8 0X99 0xD8
EFuse: 0xFF 0x62 0xFD

The only difference which my chip appears to have vs boards.txt that came with Arduino is the Extended Fuse FF vs FD which I believe has an impact on brown-out detection but not sure this would be causing my issues. I have tried to change my fuse to match with instruction and it seems to work but when I reconnect chip, the fuses are all back to original values:

./avrdude -v -v -v -v -p m2560 -C /Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -D -c wiring -P /dev/tty.usbserial-A502FUY2 -U efuse:w:0xFD:m

Given the fuses wouldn't stay programmed, I then looked at my Lock bits and think this could be where the issue lies. I write to an intel hex file and see values which I believe just means 0x18 which i think is 00011000 in binary:

:0100000018E7
:00000001FF

From the Datasheet, my lock bits mean (LB2:1 = 00, BLB02:01 = 10):

"Further programming and verification of the Flash and EEPROM is disabled in Parallel and Serial Programming mode. The Boot Lock bits and Fuse bits are locked in both Serial and Parallel Programming mode.(1)"

"SPM is not allowed to write to the Application section."

Any thoughts on the issue? Could be something completely different and I'm barking up the wrong tree :blush:

Thanks again.

Hi, welcome to the forum. I hope we can solve this for you while you are still hairy :smiley_cat:

This is the best fuse site : AVR® Fuse Calculator – The Engbedded Blog

Do you upload a sketch with a programmer ? And you don't use a bootloader ? Which programmer do you use ? an Arduino board ? which board ?

The Arduino IDE works like this:
Normal upload via usb-serial-RX/TX with a bootloader.
Upload a sketch with a programmer is possible, the bootloader is removed.
Burning a bootloader with a programmer will also set the fuses.

That means that when you burn the bootloader from within the Arduino IDE, also the fuses are set to the proper values as defined in boards.txt.
Can you burn a bootloader and use the RX/TX with a usb-serial converter to upload a sketch ?

Thanks, that link looks like a very useful resource.

I have just been uploading the sketch using a USB cable through the Arduino IDE (or AVRDude directly through Terminal). AVR ISP mkII is selected under "programmer" but I was under the impression that this was only relevant if using a special device to upload?

There are two possibilities to upload a sketch with the Arduino IDE:
The normal upload uses the usb-serial via RX/TX and the bootloader.
The upload with a programmer uses a programmer and the bootloader is removed.

I assume that you did not use a programmer. That is a special device, but also an Arduino can be used as a programmer (search for : ArduinoISP).

Do you know what kind of bootloader is in the ATmega2560 chip ?
The bootloader for the ATmega2560 chip was improved one or two years ago. If you have an old one, it might cause problems.
Perhaps the bootloader was corrupted, and that is why you get the error messages. Or something changed in the hardware. It is possible that the ATmega2560 chip is half-blown, I mean that it is working but a pin could be damaged.

Check the hardware, try to burn a new bootloader, and if that doesn't help you need a new board.

Yes, I only connected via USB. I was messing around with Eclipse C/C++ IDE though so not sure if this somehow messed up the chip when I tried to upload... I'm just puzzled as I can upload once so that would suggest encouragingly that the chip is not completely ruined but perhaps this is false hope.

I'm not sure what boot loader is on it, it came as part of a larger IC for an autopilot system (hence would be pretty annoying if its blown :frowning: ) Is there anyway I can check this and if it's still working properly and not corrupted? My other thought was to get a programmer and reprogram the bootloader.

Huzzah! I seem to have solved the issue for now by uninstalling the AppleUSBFTDI (eep) and installing another as outlined here:

https://learn.sparkfun.com/tutorials/how-to-install-ftdi-drivers/mac

Thanks for your help all the same, appreciate it!