Go Down

Topic: [SOLVED] Problems with programming ATMEGA2560 using USBasp / Arduino as ISP (Read 8049 times) previous topic - next topic

chillman

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

CrossRoads

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:
http://www.gammon.com.au/breadboard
http://www.gammon.com.au/forum/?id=11635
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

chillman

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.

chillman

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.

DrAzzy

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.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

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 :)

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



chillman

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

Bambo_Klaat

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!

pert

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: https://github.com/arduino/Arduino/issues/388

dmjlambert

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?

Ankit61195



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 :)

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,

pert

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.

Go Up