Cannot connect AVRdude to Mega2560

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally I cannot stand the arduino IDE for multiple reasons that I could write an essay on and be here for days.  However I purchased an Arduino Mega 2560 to do development on a current project of mine that will use an ATmega2560 and plan to program it in C like most MCUs.  At first I thought Eclipse CDT was being weird but when I went into cmd and started mucking around with avrdude directly, I found that I cannot get my computer to talk to my arduino board.

Reguardless if I don't specify the baud rate, or use stk500v2 instead of arduino, I cannot get it to even acknowledge the device.  The arduino IDE will write sketches no problem.

 

In the terminal if I try: 
 

avrdude -p atmega2560 -b115200 -c arduino -P COM3

 

Error: stk500-getsync(): not in sync

 

<avrdude -p atmega2560 -b115200 -c stk500v2 -P COM3>

 

timeout

Leaving the baud rate out on both lines makes no difference.  The Rx on the board will occasionally blink but not like when a sketch from the arduino IDE is being uploaded.  I have no clue what I am doing wrong.

Last Edited: Sun. Apr 19, 2015 - 09:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Add a number of -v's to the command line for avrdude to tell you more about what's wrong. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just use:

avrdude -p atmega2560 -b115200 -c wiring -P COM3

The MEGA2560 bootloader expects 115200 baud and avrdude defaults to 115200 anyway.   So you don't need the -b switch

 

-c arduino is just stk500v1 with DTR wiggle.

-c wiring is just stk500v2 with DTR wiggle.

 

So if you have nimble fingers,   you could use the stk500v? arguments.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using a atmega2560 with an arduino UNO as programmer.

I have succes with:

avrdude -p m2560 -P com4 -c stk500v1 -b 19200

115200 baud is also not working for me,  but 19200 baud is

 

Cheers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are using the ArduinoISP sketch as ISP programmer.  Hence -c stk500v1 -b 19200

The OP is using the Arduino Mega bootloader.    Hence -c wiring -b 115200

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't have wiring as a programmer, I have arduino, stk500 and stk500v2.  Using stk500v2 I am still getting avrdude: stk500_2_ReceiveMessage(): timeout
 

I went into the device manager and found the device was operating on 9600, so I changed it to 115200 and still nothing.
 

EDIT:  I think to make things more complicated, I noticed my Arduino has the .org website instead of the .cc site.  Over on the .org site it says that the Mega uses the old stk500 protocol.  So if I try -c arduino (the stk500 1.x) i get avrdude:stk500_getsync(): not in sync: resp=0x00;
 

Both errors when searched only result in those errors coming from the arduino IDE and the solutions don't apply to me since using the IDE to flash the chip works. 

Last Edited: Sun. Apr 19, 2015 - 08:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If your MEGA2560 works perfectly with the Arduino IDE,   there is clearly no great problem.

 

You don't have to use Arduino language to create the HEX.     I write in C or C++.    Then upload to the Arduino board via its bootloader.

 

AFIK,   the MEGA2560 has always used the "avrdude -c wiring" command.    I use it regularly with the CV IDE or the AS6 IDE.

 

Of course,   if you ever connect an external ISP programmer to the 3x2 ISP header,   you end up destroying the bootloader.     But you can not do any harm with the regular USB connection to the PC.

 

David.

 

p.s. if you tick the verbose box for uploading in the Arduino Preferences,   you can upload an empty sketch.    Then see what the IDE was actually using.  e.g.


C:\Program Files\Arduino-1.7.0/hardware/tools/avr/bin/avrdude -CC:\Program Files\Arduino-1.7.0/hardware/tools/avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM12 -b115200 -D -Uflash:w:C:\Users\DAVIDP~1\AppData\Local\Temp\build7259766068610796026.tmp/sketch_apr19a.cpp.hex:i 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So doing that I got:

 

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM3 -b115200 -D -Uflash:w:C:\Users\TEHPWN~1\AppData\Local\Temp\build7616902960017732577.tmp/Blink.cpp.hex:i 

and during upload:

 

Using Programmer:  wiring
Programmer Type:   wiring
Description:       wiring
Programmer Model:  AVRISP

 

wiring can't be found and -c AVRISP still gives me the stk500_getsync(): not in sync error.  It might have helped that I am using WinAVR to flash the chip, not the AVRdude that comes with the Arduino IDE.  I am doing that becuase I intend to use Eclipse CDT to write and upload code and it uses WinAVR, I am just doing command lines to troubleshoot why AVRdude can't connect up.

Last Edited: Sun. Apr 19, 2015 - 09:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please copy-paste your equivalent command to the one that I posted.

 

"wiring" is simply a name for the protocol that avrdude uses to talk to the MEGA2560 bootloader.

It is not a physical device.

 

Do you possess an Atmel AVRISP or Atmel AVRISP-mkII ?

The mkII has a blue transparent case with ATMEL written on the outside.

 

If you do own a real ISP programmer,  you have probably destroyed the bootloader.

You can select it in the IDE and restore the bootloader.

Then dig a deep hole.   Bury your ISP programmer.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not have a physical ISP device, and the bootloader is perfectly fine as I can yet still upload sketches through the Arduino IDE.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The good news is that "nothing can be broken" if you don't have a physical ISP programmer.

 

Please copy-paste the result of a verbose upload of an empty sketch.   e.g. New

This gives a whole lot of information about which version and IDE you are using.    If you want a solution,   this info is essential.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrdude: Version 6.0.1, compiled on Mar 30 2015 at 14:56:06
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         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      : 43.5 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801
avrdude: reading input file "C:\Users\TEHPWN~1\AppData\Local\Temp\build5006867017877907712.tmp/sketch_apr19a.cpp.hex"
avrdude: writing flash (642 bytes):

Writing | ################################################## | 100% 0.12s

avrdude: 642 bytes of flash written
avrdude: verifying flash memory against C:\Users\TEHPWN~1\AppData\Local\Temp\build5006867017877907712.tmp/sketch_apr19a.cpp.hex:
avrdude: load data flash data from input file C:\Users\TEHPWN~1\AppData\Local\Temp\build5006867017877907712.tmp/sketch_apr19a.cpp.hex:
avrdude: input file C:\Users\TEHPWN~1\AppData\Local\Temp\build5006867017877907712.tmp/sketch_apr19a.cpp.hex contains 642 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.10s

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

avrdude done.  Thank you.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheWinterSnow wrote:

So doing that I got:

 

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM3 -b115200 -D -Uflash:w:C:\Users\TEHPWN~1\AppData\Local\Temp\build7616902960017732577.tmp/Blink.cpp.hex:i 

and during upload:

 

Using Programmer:  wiring
Programmer Type:   wiring
Description:       wiring
Programmer Model:  AVRISP

 

wiring can't be found and -c AVRISP still gives me the stk500_getsync(): not in sync error.  It might have helped that I am using WinAVR to flash the chip, not the AVRdude that comes with the Arduino IDE.  I am doing that becuase I intend to use Eclipse CDT to write and upload code and it uses WinAVR, I am just doing command lines to troubleshoot why AVRdude can't connect up.

 

Sorry.   I think that I missed your post.   Or you were editing it when I was typing my reply.

 

From that command line,   you can see where the Arduino keeps its private copies of avrdude.exe and avrdude.conf

 

In the old days,   WinAVR would install avrdude for you.    I am not sure whether AS6 installs avrdude at all.     Or if it does,   whether your command line knows its location in your PATH.

 

Just type "avrdude -v" and see which version and which CONF it is using.    If it is a very old avrdude,  it might not know "wiring".

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

version 5.10

 

The arduino version is 6.0.1

I have the latest version of WinAVR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So after mucking around a bit I got the Arduino version of AVRdude to work in the command terminal, so I moved my path in Eclipse to that version, now I get this:

 

avrdude: stk500v2_command(): command failed

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am confused.    The bootloader is obviously ok because the Arduino IDE uploads code to the MEGA2560 board correctly.

 

There is nothing clever about the IDE and avrdude.

You just need to invoke the 'same' command with your own HEX file.

 

The simple checks are to add -v to the command.

This will show which version of avrdude.exe and avrdude.conf are actually being used.

 

Since bootloader comms just use the virtual COM port,   there is nothing much to go wrong.

The "wiring" protocol does a wiggle of the DTR line.     This is what makes the bootloader start.  (and is a lot easier than pressing a RESET button by hand)

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I finally figured it out, after messing around with some stuff I realized that the arduino IDE was not outputting all of its parameters to AVRdude so when I copied it and tried to use it, I didn't see that it wasn't specifying the COM Port.  Also when I got that fixed, the Arduino IDE had specified the config file location and so I just copied that along, but because the C:\Program Files... has a space in it, it was setting the config directory to C:\Program and therefor wasn't finding wiring or any other programmer.

Yesterday when I was messing around with the arduino files I made a copy of the config file and put it in the same location as avrdude, so I don't need to specify the location of the config file at the moment, however for future reference, what is the correct path syntax for spaces?  What makes it worse about that syntax is that what it did with my user name makes no sense, so I am not quite sure what to do with folders that have spaces in their name.

 

Last Edited: Mon. Apr 20, 2015 - 10:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Life is much simpler if you avoid spaces in filenames when you use a command line.

If you do,   enclose the argument in quotes.

 

When you use a command line,   you either use full path names or you let it find the command by searching the directories along the $PATH.

It will use the first file that it finds along the PATH that matches.

 

This is why you were asked for the result of "avrdude -v"

 

Note that Windoze has little concept of sensible places to store user executable files.    It expects you to browse to a directory and do everything from there.

Personally,   I have a personal "utils" directory that contains EXE or BAT files.    And I put my "utils" directory at the front of the PATH.

 

So my "avrdudewait.bat" uses a specific known version of avrdude in a specific location.

But I can call it from anywhere on the disk.   (and use "filename with spaces .hex")

 

David.

Last Edited: Tue. Apr 21, 2015 - 06:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the 'wiring' configuration is not present after installing winavr, chances are, your AVRDude is too old.. I just had that same problem, but after updating avrdude.exe, avrdude.conf and libusb0.dll from the link below, everything appears to be working (if using eclipse and AVR eclipse plugin, you need to restart eclipse for 'wiring' to show up).

 

http://cnlohr.blogspot.dk/2014/0...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting info but I can't help thinking that if he hasn't resolved it in the last 18 months (date of previous post in this thread) he's probably given up on AVRs by now!