0

I created a custom Arduino based off the Mega2560 R3. It uses the ATMega16U2 uC as the USB interface between ATMega2560 uC and the PC.

The bootloader on the 2560 is uploaded by using an Arduino Micro via ArduinoISP. I followed this tutorial from Instructables on uploading the bootloader/firmware for the 16U2 except I modified some parts for the 2560 instead of the UNO. Here is my added section in the /program Files (x86)/Arduino/hardware/arduino/avr/boards.txt

unorestore.name=MEGA2560 16U2 Restore Firmware
unorestore.bootloader.tool=arduino:avrdude
unorestore.bootloader.low_fuses=0xff
unorestore.bootloader.high_fuses=0xd9
unorestore.bootloader.extended_fuses=0xf4
unorestore.bootloader.file=Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex
unorestore.bootloader.unlock_bits=0x3F
unorestore.bootloader.lock_bits=0x0F
unorestore.build.mcu=atmega16u2
unorestore.build.f_cpu=16000000L
unorestore.build.board=uno.build.board=AVR_MEGA2560
unorestore.build.core=arduino:arduino
unorestore.build.variant=standard

The problem is after I upload a sketch (with a size say over 10 kB), I can't upload any new sketch and get this timeout error message instead as shown below. Not even a simple blink sketch. The TX and RX LED connected to the 16U2 uC that flashes during an sketch upload doesn't even blink once.

enter image description here

The only way I can get it take another sketch is to "re-flash" the bootloader on the 2560 uC via ArduinoISP. The TX and RX led now flashes during the sketch upload. Of course, this is a huge hassle as I don't want to do "re-flash" the 2560 bootloader every time I want to upload a sketch.

I don't have this problem on my Elegoo Mega2560 R3 clone board so I'm thinking it might be something wrong with my 16U2 firmware/bootloader. Anyone have any idea what else might be causing this?

enter image description here

  • 2
    Why are you compiling for the atmega16u2? – Majenko Oct 6 at 21:27
  • the first upload after flashing the bootloader doesn't require a reset to bootloader. following uploads require a reset before upload. does your auto-reset circuit work? – Juraj Oct 7 at 5:23
  • @Majenko that is the selection for burning the bootloader onto the ATMega16U2 via ArudinoISP. – Agriculex Oct 7 at 13:19
  • @Juraj I never heard of this before. I pretty much copied the official schematic. Is the reset the same as pulling the reset pin on the 2560 to ground before the sketch upload? – Agriculex Oct 7 at 13:22
  • You shouldn't be uploading a bootloader to the 16U2. You install the CDC/ACM firmware over DFU. Are you sure you aren't installing the 16U2 bootloader onto the Mega2560? – Majenko Oct 7 at 13:25
1

Your RESET circuit is wrong.

  • You have no pullup resistor on the RESET pin of the ATMega3560.
  • You have an extraneous pulldown resistor on the D7 pin of the 16U2.

That means your 16U2 will not be able to trigger a reset of the ATMega2560 to run the bootloader.

Remove the pulldown on D7 of the 16U2 and add a 10kΩ pullup to the RESET pin of the ATMega2560. Without that pullup:

  1. The chip may not run properly as RESET is floating (it may have an internal pullup, I can't recall)
  2. The capacitor linking the 16U2 D7 and RESET of the ATMega2560 won't be able to generate a proper reset pulse. This will be exacerbated by the 1kΩ pulldown.

On the Mega2560 reference schematic RN1A is the pullup in question.

| improve this answer | |
  • Thanks a lot for your find! Really appreciate it! I'll add the pull up resistor RN5A. As for the pull down resistor on D7 of the 16U2, it's from RN3D on the reference schematic. I'll remove that then. It said it's for USB Boot En. – Agriculex Oct 7 at 15:32
  • I think that means it's for enabling DFU mode on the 16U2 - it may be related to why you can't use flip? – Majenko Oct 7 at 15:38
  • I was able to use the Flip software to upload the Uno hex file to a fresh new 16U2 but it can't just for the mega hex file. It said it was too large. Anyways, I added the pullup resistor and removed the pulldown resistor and it works now! I can upload a new code without having to re-flash the bootloader. You saved a huge amount of time for me. Would you accept a small tip via paypal if that's allowed? It's not much but as a way of thanks for your time. – Agriculex Oct 7 at 16:05
  • Wow. If you really want to, sure. There's a "donate" link on UECIDE.org that goes to me if you really want to. – Majenko Oct 7 at 16:16
  • Majenko, I don't see a schematics in the question – Juraj Oct 8 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.