So I've created a PCB with an Atemga2560, a SIM808 module and other stuff.
I've susccessfully burned the bootloader and uploaded a test sketch for an I2C temperature sensor; everything works fine.
The problem comes when I try to upload another sketch, it is unable to do so:
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 : COM13
Using Programmer : wiring
Overriding Baud Rate : 115200
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
The problem is solved by reburning the bootloader and uploading the sketch. But I don't think it is elegant and moreover I think I've already destroyed an atmega chip for that reason (or maybe not, but it's impractical to reburn the bootloader every time I need to upload a sketch).
The circuit related to the atmega2560 uC has already been used on another project with no troubles at all.
The disposition of components has changed, but taking into account that the first time the sketch is uploaded successfully makes me think the problem is somewhere else.
So I've tried in a different PCB that I've also designed and I have the same problem. And since that second PCB is the same as the 1st gen PCB mentioned before and that is working I'm starting to suscpect of the atmega2560 uC which where bought from a diffrent vendor.
It seems like it's not the vendor's uC fault becuase I've tried the chip that was working on the first gen protoype and is also giving the same problems.
I'm starting to run out of ideas...
The DTR line of the serial adapter should be connected to one side of a 0.1uf ceramic cap. Other side should be connected to the reset pin on the '2560, which should also be connected to a 10k resistor to vcc.
Without that, you need a precisely timed manual reset right at the moment that the sketch finishes compiling, before it starts uploading, so it can enter the bootloader to receive the upload.
It works the first time because the rest of the flash is empty (0xFF in all addresses not part of the bootloader; FFFF is a no-op, so when the bootloader tries to execute the sketch, execution runs by all the FFFF no-op's until it gets to the bootloader again, so the bootloader runs essentially continually.
DrAzzy:
Do you have the DTR auto-reset circuit present?
The DTR line of the serial adapter should be connected to one side of a 0.1uf ceramic cap. Other side should be connected to the reset pin on the '2560, which should also be connected to a 10k resistor to vcc.
Without that, you need a precisely timed manual reset right at the moment that the sketch finishes compiling, before it starts uploading, so it can enter the bootloader to receive the upload.
It works the first time because the rest of the flash is empty (0xFF in all addresses not part of the bootloader; FFFF is a no-op, so when the bootloader tries to execute the sketch, execution runs by all the FFFF no-op's until it gets to the bootloader again, so the bootloader runs essentially continually.
Yes, that was the problem. I screwed up with the DRC of the PCB and that line was missing.
Thanks