AVRDude flashing atmega2560 through atmelstudio 7

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

I am trying to flash my made program to the atmega2560 by using a "external tool" which command the avrdude. When I flashed my atmega328P using the following code everything was working.

-C "C:\avrdude\avrdude.conf" -p atmega328p -c arduino -P COM6 -U flash:w:"$(ProjectDir)Debug\$(TargetName).hex":i

But for my project I needed to upgrade from the atmega328p to the atmega2560. But when I try to flash the 2560 using the following code, it is not working correctly.

-C "C:\avrdude\avrdude.conf" -p m2560 -D  -c wiring -P COM3 -b 115200 -U flash:w:"$(ProjectDir)Debug\$(TargetName).hex":i 

The cmd commandpromt opens up and show that the flash was executed correctly, but the code I flashed seems not to be running.

 

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x1e9801
avrdude.exe: reading input file "C:\Users\Phanteks\Documents\Atmel Studio\7.0\WS2815_1.0\WS2815_1.0\WS2815_0.1\Debug\WS2815_0.1.hex"
avrdude.exe: writing flash (5090 bytes):

Writing | ################################################## | 100% 0.74s

avrdude.exe: 5090 bytes of flash written
avrdude.exe: verifying flash memory against C:\Users\Phanteks\Documents\Atmel Studio\7.0\WS2815_1.0\WS2815_1.0\WS2815_0.1\Debug\WS2815_0.1.hex:
avrdude.exe: load data flash data from input file C:\Users\Phanteks\Documents\Atmel Studio\7.0\WS2815_1.0\WS2815_1.0\WS2815_0.1\Debug\WS2815_0.1.hex:
avrdude.exe: input file C:\Users\Phanteks\Documents\Atmel Studio\7.0\WS2815_1.0\WS2815_1.0\WS2815_0.1\Debug\WS2815_0.1.hex contains 5090 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 0.54s

avrdude.exe: verifying ...
avrdude.exe: 5090 bytes of flash verified

avrdude.exe: safemode: Fuses OK

avrdude.exe done.  Thank you.

I am trying to address a RGB strip and currently it emits the colour green. And in the newly flashed code it was set to blue, but it still emits green. When I try the same code using the Arduino IDE the colour changes to blue, so apparently the arduino IDE avrdude has a correct configuration. But what every command configuration I try to use nothing seems to work.

Does anyone have any clue to what might be the issue here?

This topic has a solution.
Last Edited: Sun. Jan 12, 2020 - 08:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Obitboot on the Uno will erase the flash without being told.

 

My guess is that the wiring bootloader does not, so you need to tell it.

 

manual page for avrdude

           -e      Causes a chip erase to be executed.  This will reset the contents of the flash ROM and EEPROM to
                   the value ‘0xff’, and clear all lock bits.  Except for ATxmega devices which can use page erase,
                   it is basically a prerequisite command before the flash ROM can be reprogrammed again.  The only
                   exception would be if the new contents would exclusively cause bits to be programmed from the
                   value ‘1’ to ‘0’.  Note that in order to reprogram EERPOM cells, no explicit prior chip erase is
                   required since the MCU provides an auto-erase cycle in that case before programming the cell.

 

avrdude -p m2560 -D  -c wiring -P COM3 -b 115200 -e -U flash:w:blink.hex

my projects: https://github.com/epccs

Debugging is harder than programming - don’t write code you can’t debug! https://www.avrfreaks.net/forum/help-it-doesnt-work

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

I tried adding the e but ended up with the following error message.

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x1e9801
avrdude.exe: erasing chip
avrdude.exe: stk500v2_command(): command failed

avrdude.exe done.  Thank you.

 

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

Your -c wiring arguments look fine.    You do not need -e but it probably does no harm.

 

I suspect that your AS7.0 code is wrong.    Please "clean" the project.   Then Zip up the specific Project folder.   Attach the project.zip file

 

The beauty of Arduino hardware is that everyone in the world can re-build your AS7.0 project (and debug it for you)

 

David.

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

I was thinking the same thing, but as the Arduino IDE is able to flash it (the same code as AS7.0 would flash) and it really does change the arduino output, I assume it is working correctly. And also when I flash the same code using AS7.0 to the arduino uno it is all working correctly

 

 

But this is my code, see attchement.

Attachment(s): 

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

The erase command isn't enabled as each flash page is erased before writing.

https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/stk500v2/stk500boot.c#L999

 

version mis-match between AVRDUDE (loader) and the bootloader?

 

more likely is the path to AVRDUDE.EXE is incorrect.

Arduino to Atmel Studio 7 external programmers, ISP and serial programming | AVR Freaks

 

bootloader mis-match to AVRDUDE?

https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/stk500v2/stk500boot.c#L257

 

"Dare to be naïve." - Buckminster Fuller

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks for the AS7.0 ZIP.   (actually you used RAR which is less convenient)

 

The AS7.0 project is configured for ATmega328P

The ArduinoCore is configured for ARDUINO_AVR_UNO

 

I suggest that you build your Arduino project in the Arduino IDE (with Board = MEGA2560,  Port = Arduino Mega2560).

Build and test with the reliable Arduino IDE.

 

If you really want to import into AS7.0 follow the AS7.0 instructions (with Board = MEGA2560)

This creates a different project for MEGA2560

 

Note that the Arduino IDE is far more sophisticated.    You can build the same sketch for Uno, Mega, Zero, Due, ... by simply changing the Board in the IDE.

 

If you have a problem,   Zip up your AS7.0 project like you did for the UNO project.

 

David.

Last Edited: Sun. Jan 12, 2020 - 08:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thank you for the help, that was indeed the problem. All I needed to do was a new project creation based on the atmega2560 build.

 

I am sorry for the .rar I didn't notice it, just used the shortcut in the file explorer.

 

I am used to AS because of my study, we needed to program in embedded c and where not allowed to use any of the arduino libraries. But I am currently working on a project of my own. So I wanted the view of AS (because I am used  to it) and at the same time the ease of the arduino libs.

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

I am pleased that you have solved your problem.

 

Give my regards to Scout and Silver.

 

David.