Fail to burn bootloader into standalone atmega2560

Hello, I am making a project where I use standalone atmega2560. I used arduino mega schematic to put all necessary components so atmega2560 would be working. I tried to burn bootloader into it using arduino mega as ISP, but failed. I get this error:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cstk500v1 -PCOM4 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xFF:m 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

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

         Using Port                    : COM4
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
         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 : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x000000 (retrying)

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

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

I use schematic which I attached.

At first I uploaded arduinoISP example code to my arduino mega and then used it to program several arduino megas to be sure that it is working and then I connected cables to arduino mega ISCP connector which is master and then put them into my PCB board X3 connector which also has SPI connected to it. After trying to burn bootloader I got an error above.

Things I already did:
Made sure that all VCC pins are connected. And AVCC is connected to VCC
Made sure that all GND pins have ground and my PCB has same GND level as arduino mega (programmer)
Made sure that I connected SPI correctly.
Made sure that arduino as ISP is working.
Made sure that VCC level is high (it is about 4.7 V)
I also tried to put external voltage, but it also did not help.
I tried putting capacitor between Reset and GND pins on arduino mega (programmer)

What could go wrong? After all my struggles I came to the conclusion that it is probaby hardware problem, but I cannot find it.
Also I read that atmega2560 by default use 8 MHZ internal clock, can it be a problem?

Your reset / crystal setup is wrong!

What is wrong?
It needs to be like this?

Screenshot_2.jpg

Yes. :) - Kind of, the 1M resistor should be over 33 & 34 with no R19

I fixed as you suggested, still I get the same error. This is how it looks now:

Screenshot_1.jpg

Try removing R20 & C7

It did not help... I'm wondering, if atmega use internal clock with default fuses can external clock be an issue?

No, I program 328s and 2560s from the factory on boards with the crystal wothout issues.

I see. Thanks for your help. Any other ideas?

post an in focus close up photo of your board!

When the internal clock is enabled (default for bare chips) the external crystal is ignored. You must explicitly set the fuses for it to use an external clock input (crystal).

Remember to connect the RESET of the ISCP header to the reset pin (the label disappeared in the snippet of #4). The 10k pull-up should not be necessary.

Have a look at the schematic for the mega 2560. Check your oscillator is running if you have a scope .

Check you have power supply and 0v in the right places and no pins shorted to ground or supply. Crystal and 22pf should be close to the processor . I use a cheap ICSP programmer from eBay and gave not had any issues with 1284, 328 processors .

Any internal settings of the processor get over written when boot loading . Are you selecting mega 2560 in the processor options ?

OP gets a device signature of 0x000000 which implies the ICSP is not connected properly to the processor, as there is no response whatsoever.

The X3 header is not in the classic ICSP footprint, could that be the issue here? if using a standard programmer, this will not work, the normal is :

MISO VCC SCK MOSI RESET GND

With MISO on pin 1

missdrew: The X3 header is not in the classic ICSP footprint, could that be the issue here?

Good one! KiCAD has the ICSP footprint with proper labelling (choice of the 6 and 10 pin versions, I've never seen the point of the 10-pin one, just takes up a lot more space) in the standard library, making it very easy to get that right, so I didn't think of checking on that...

Thank you for all your help, it gives me hope. I will reply to each of your suggestions:

wvmarle

I tried removing R23 pullup resistor, it did not help. I connected RESET in programmer (arduino mega) to digital pin 10 and in my PCB side I connected it to atmega2560 RESET pin which is atmega2560 pin 30.

Hammy
I already checked mega schematic, I basically used it to make my board.
Sadly I do not have oscilloscope, so I cannot check oscillator. But oscillator can’t be a problem if fresh atmega2560 use internal clock. Am I right?
I checked again, no shorts, there are GND and VCC in all right places.
Crystal and 22pF caps are 3-5 mm from the MCU.
How do I check if internal settings get overwritten? I only get a message I showed you. Is there a way to check it?
And yes I select Arduino mega 2560 as a processor in arduino IDE

Missdrew
I am aware that header pinout is not a standard one. I use separate wires so it is not a problem. But I should keep in mind to use a standard pinout in the future

My other testing today and yesterday:
I noticed that resistance between GND and VCC was 600 ohms and I found out that it came from my power circuit, so I cut the track which goes there and now it is about 1.2 M ohms between VCC and GND. Still it did not help. I think just after this during my programming I noticed that instead of avrdude: Device signature = 0x000000 I received Device signature = 0xffffffff , but I could not repeat it again. Maybe it was just a coincidence…

I attached photo with my connections, it was difficult to capture all colors at once. This connector is connector X3 in my schematic and blue wire is pin 2 (MOSI), pin 3 gray (MISO), pin 4 purple is GND and so on.

Maybe you can give your opinion if schematic looks fine or not. If it looks ok, maybe I should consider trying another MCU, maybe this one was destroyed while soldering, arrived dead or was killed by static electricity?

Did you verify your programmer is working correctly - by using it to program another Arduino Mega, Uno or Nano board? Those have the ISP headers conveniently broken out (using the standard pinout).

Yesterday I decided to check all connections between all MCU pins and I found out that atmega pins 3 13 23 42 52 63 73 90 and 85 are shorted to each other even though PCB has no tracks connecting them. So MCU was dead and after replacing it works! Thank you all for your help