Problems uploading code via serial USB

Hello guys, I'm experiencing an issue while trying to upload my codes using the Arduino IDE via USB serial to my board, my board is using an ATmega2560 and works similar to an Arduino Mega 2560, I burned the bootloader on the ATmega2560, and the firmware on the ATmega16U2, I can upload the code to my board with the USBasp programmer without any problems, but using the USB serial it's a little bit difficult. After months of trying to solve the problem I accidentally made different Fuses and Lock Bits settings, and it worked, but only when I burn the bootloader and upload the code for the first time, when I try to upload for the second time it doesn't work, so I have to upload the bootload again every time that I want to upload the code via USB serial, and I want it to work every time. I think that I only have to make a new setting in the Fuses and Lock bits, so can you guys help me with it? below are my currently Fuses and Lock bits settings, that is working when I try to upload for the first time, what should I change? Thanks in advance!!

Usually the "can only upload once after burning bootloader" symptom is caused by your board's auto-reset circuit not working.

Normally you need to do a hardware reset of the microcontroller to activate the bootloader, then start an upload before the bootloader times out and starts the user application. However, after burning bootloader the bootloader is perpetually activated so no reset is necessary, meaning the first upload will work with or without a reset.

The auto reset circuit (for an example, see these "minimal setup" schematics) is the DTR pin of the USB-TTL serial chip connected to the reset pin of the microcontroller via a 0.1 uF capacitor. In combination with the pull-up resistor on that pin, it generates a reset pulse when the serial connection is opened.

To test this, you could see whether uploads work after a manual reset. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. If you reset the microcontroller immediately after pushing the button, the bootloader will have timed out by the time the upload actually starts. The way to get the timing right is:

  1. Select Sketch > Upload from the Arduino IDE's menus to start an upload (or click the upload button or whatever you prefer).
  2. Watch the black console window at the bottom of the Arduino IDE window until you see something like this:
    Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
    Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. 
    Maximum is 2048 bytes.
  3. Immediately press and release the reset button. The upload should now finish successfully.

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