[SOLVED] Problems with programming ATMEGA2560 using USBasp / Arduino as ISP

Hello all,

I made a custom PCB with a ATMEGA2560 for a project. So far there is nothing on the board except the microcontroller, a 16Mhz resonator and a ICSP header. My plan was using a ISP to upload my sketches to it, but I can't get it to work. I have a USBasp V2.0 or an Arduino Mega 2560 available to program the ATMEGA2560.
I've tried both the USBasp and the Arduino as ISP with no success. There are no error messages but the Microcontroller simply doesn't do what it's supposed to. I've also tried to burn the Arduino bootloader on the chip, which also runs without error messages, but afterwards Pin 13 flashes in a different pattern as you'd expect: a fast double flash with a longer pause in between instead of the simple 1s on, 1s off. So maybe that's a clue to what's going on? Is the ATMEGA2560 simply damaged maybe? Problem with the resonator?

I successfully burned the arduino bootloader to the Arduino mega using the USBasp and have also successfully buned the bootloader and uploaded sketches on a Arduino nano using the Arduino as ISP.
I've tried the slow SCK mode on the USBasp as well.

I've only tried uploading blink sketches with different blink patterns so this can't be a problem with the sketches themselves.

Any help would be greatly appreciated!

Tillman

Try adding the 10K reset pullup resistor to Vcc, and 0.1uF caps from each VCC & AVCC pin to Gnd.
You do have power going to all VCC & AVC pins, and all GND pins connected to Gnd?
Try Nick Gammon's bootload installer sketch, one of these two:

Thank you for the input! I will try all of that later. I tried to program my Arduino Mega using an Arduino Nano to make sure that the problem is with my pcb. It turns out that while I can burn the bootloader on the Arduino Mega just fine, uploading sketches with programmer does not work on the mega. They upload without errors but do not execute. So there seems to be a problem programming the ATMEGA2560 in general with my approach.
To clarify, I'm not planning on using the Arduino bootloader with the homemade PCB, I currently don't even have the pins accessible for serial programming. I just tried burning the bootloader to see if it works.

Ok so I solved the problem that sketches uploaded with programmer are not executed on the mega. (If someone else has this problem the solution was posted here )
My homemade PCB is still not working though so I will try the suggested hardware modifications.

If you do not have decoupling capacitors on a microcontroller, you should not expect it to work. If it does, it will half-work, and reset, or maybe flash writes will fail, or it'll reset when you use certain peripherals. You really do need the decoupling caps. 0.1uf between power and ground, for each power pin, as close to the pin as possible.

It's working! Can't believe it ^^ It was in fact just a problem with the fuses as discussed in the link I posted.

Here's the complete fix step b step for future reference since I as a beginner had some trouble following it correctly:

  1. Copy the code from this post

  2. Go to C:\Program Files (x86)\Arduino\hardware\arduino\avr (or whereever Arduino is installed on your computer)

  3. Open the boards.txt in that folder and paste the code in it, save the file (you might have to remove write protection)

  4. Restart Arduino IDE

  5. Now there should be an additional processor available under tools/processor called "ATmega2560 (Testato ISP Version", select that processor

  6. Burn the bootloader once with these settings

  7. That's it! Now uploading sketches with USBasp works flawlessly :slight_smile:

Thanks go out to Testato and NicoHood for figuring out this fix!

Thank you all for your kind suggestions on PCB layout. This is my first PCB so bear with me :slight_smile:

never late to say Thanks for pointing the right answer! works perfect even using UNO as an ISP programmer. ready to buy a USBasp for fast connections :). Thanks!

There are now ways to fix this issue on both USBasp and Arduino as ISP without changing the fuses. This is useful because the BOOTRST setting that allows Upload Using Programmer to work with ATmega2560 makes serial uploads no longer work meaning you have to change the fuses each time you wanted to go from one upload method to the other.

The solution for USBasp is to update the USBasp firmware to PeterVH's version. More information here:
http://forum.arduino.cc/index.php?topic=363772

The solution for Arduino as ISP is to use Boards Manager to update to Arduino AVR Boards 1.6.14 or newer(1.6.14 is the current version at the time I'm writing this). This will install AVRDUDE 6.3.0 which solves the Arduino as ISP issue.

More information at the GitHub report for this issue: Program doesn't run after Upload Using Programmer with USBasp (Mega2560) · Issue #246 · arduino/ArduinoCore-avr · GitHub

I read the github issue and this thread and don't understand what has happened here. I can understand the avrdude version may be related to addressing the large memory of the ATmega2560, but I do not understand how it could fix an issue that has to do with where the BOOTRST fuse points, and the fact that the ATmega2560 does not wrap around and start again at address 0 to run the sketch. Sorry for being dense, but I just don't get it.

Can you please explain to me how avrdude version upgrade removes your need to make sure the BOOTRST fuse is programmed if you want the bootloader to run and unprogrammed if you want the user program to run when you have no bootloader? Was the old avrdude version preventing the PC wrap around from happening with the ATmega2560 like it does with other chips such as the ATmega328P? Or am I missing some point?

chillman:
It's working! Can't believe it ^^ It was in fact just a problem with the fuses as discussed in the link I posted.

Here's the complete fix step b step for future reference since I as a beginner had some trouble following it correctly:

  1. Copy the code from this post

  2. Go to C:\Program Files (x86)\Arduino\hardware\arduino\avr (or whereever Arduino is installed on your computer)

  3. Open the boards.txt in that folder and paste the code in it, save the file (you might have to remove write protection)

  4. Restart Arduino IDE

  5. Now there should be an additional processor available under tools/processor called "ATmega2560 (Testato ISP Version", select that processor

  6. Burn the bootloader once with these settings

  7. That's it! Now uploading sketches with USBasp works flawlessly :slight_smile:

Thanks go out to Testato and NicoHood for figuring out this fix!

Hello,

It is working by changes in fuse bit, but new problem was arise.

In detail, when I upload code using solution given by you, watchdog of my board is not working properly. Some time controller start to reset continuously, I tried physical reset but controller reset as before. To recover the situation, I used to remove power supply and again power on it again.

This happens randomly.

If I change higher fuse bit to 0xD8 and program it by serial then everything working good.

Please help to solve my this new issue.

Thanks,

The bootloader disables the watchdog timer for you. When you upload sketches via an ISP programmer, you erase the bootloader. That means you need to handle the the watchdog timer in your own code. You should reset it as soon as you sketch starts.

I have Successfully upload the program from Arduino UNO to Arduino Mega

Step wise

  1. First upload the program (ArdunoISP) in UNO as Tool (Board UNO, Programmer as AVRISP mkll) without wiring in mega
  2. Wire the ISP from UNO (near to ON) to MEGA (Mega ISP near to Reset button) accept Reset pin. Reset pin wiring from Digital pin 10 of UNO to Reset pin of mega (in Power line).
  3. Contact the UNO as Programmer in PC
  4. Select in Tool (Board mega 2560, Programmer as Arduino as ISP)
    5 Burn Bootloader in Tool Menu after Successfully burning
  5. uploaded the your Program (Example as Blink Programme with different delay) by pressing the Shift Key (upload using programmer)
  6. enjoy