Program standalone ATmega2560 using USB AVR programmer

Hi, I have a hex file and I want to program the hex file into a standalone atmega2560 microcontroller by using a USB AVR programmer. Can anyone explain step by step to me in detail how to do it? Thank you.

Generate model command

First, we’re going to do a dummy upload in the Arduino IDE in order to get it to help us generate the avrdude command used to write the program to the Arduino board.

Note: It doesn't matter whether the upload will succeed or fail. You get the command either way.

  1. Plug the Arduino board you want to write to into your computer.
  2. Select your board from the Arduino IDE’s Tools > Board menu.
  3. Select your board’s port from the Tools > Port menu.
  4. Select File > Preferences from the Arduino IDE's menus.
  5. Check the box next to "Show verbose output during: [] upload".
  6. Click the OK button.
  7. Select Sketch > Upload from the Arduino IDE's menus.
  8. Wait for the upload to finish/fail.
  9. Scroll up the black console window at the bottom of the Arduino IDE window until you see the avrdude command that was generated for the upload. It will look something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
  10. Select the full text of the upload command.
  11. Press Ctrl+C. This will copy the upload command to the clipboard.

Customize command

Next, you need to modify the upload command to write the hex file you read from your other Arduino board:

  1. Start a text editor program.
  2. In the text editor window, press Ctrl+V. This will paste the command into the text editor. The end of the command will look something like this:
    -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
    That is the part of the command that tells it to write.
  3. Replace the filename in that part of the command with the name of the file you read:
    So now the full command looks something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:readfile.hex:i
    If the paths in the command contain spaces, wrap the paths in quotes.

Run command

Now the write command is all prepared. It's time to run it!

  1. Plug your Arduino board into your computer.
  2. Select the full text of the write command in your text editor.
  3. Press Ctrl+C. This will copy the write command to the clipboard.
  4. Open a command line terminal. On Windows, you can use the Run dialog, PowerShell, or cmd.
  5. In the command line, press Ctrl+V. This will paste the avrdude command.
  6. Press Enter to run the command.
  7. Wait for the writing process to finish successfully.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.