In Arduino Mega, bootloader does not work when watchdog is disabled

arduinoatmegaavr

In Arduino Mega (ATMEGA2560), when I enabled the interrupts, the watchdog got overflown, so the chip restarted each time the program counter achieved the interrupt enabling line.

So I tried to disable the watchdog, setting WDTCSR_WDCE to 1 and WDTCSR_WDE to 1, and after setting all WDTCSR to 0.

But when I did this, I realized that my reset pin does not work anymore. Now when I click on it, simply does not happen anything, and I cannot load a new .hex to the chip.

I burnt the bootloader again using ICSP, but the problem still happens.

Thus, how can I fix it?

Best Answer

My experience is there was 2560 bootloader provided on Arduinos (at least 2-3 years ago). Watchdog is not disabled in bootloader and because watchdog timer is not reset on non power-cycle reboot then watchdog reboot causes forever rebooting in bootloader because of timeout waiting for potential upload. You can prove it that main program starts after power cycle but not when watchdog forces reboot.

Fix was uploading non bugged bootloader.