Hello, I read that there was a bug in the Mega 2560 bootloader that causes it to hang when there are three ! in a row, I have come across this several times.
However the problem with the WDT and some older bootloaders is if the WDT is using some minimum time out value that when the system is reset the bootloader doesn't complete it's thing quick enough before the WDT triggers another reset and you are stuck in a bootloader/WDT tight loop that won't end. A proper bootloader these days resets the WDT interrupt when the bootloader starts, to prevent the WDT from tripping again.
So testing the WDT with a 8 second value won't test out the bootloader for proper WDT handling.
#include <avr/wdt.h>
void setup(){
Serial.begin(9600);
Serial.println("Hello world");
wdt_enable(WDTO_15MS);
}
void loop(){
Serial.println("I am going to not get stuck..");
for(int x=0; x<100; x++) {
wdt_reset();
x++;
delay(10);
}
wdt_reset();
Serial.println("I am going to get stuck now..");
for(int x=0; 1; x++) {
delay(10);
}
}
and i get
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
So LOL me. I loaded the WDT test using the 15msec timeout value onto a Uno board and it worked fine. So I decided to see if my old mega1280 board did indeed suffer from the WDT problem so I loaded it and bang it bricked the board with led13 blinking at a very fast rate. Couldn't load anything else via the IDE. So went to Nick's great bootloader writer and it fixed me right up, highly recommended sketch ( Gammon Forum : Electronics : Microprocessors : Atmega bootloader programmer )
Out of curiosity I tried the WDT test again on the mega board hoping that maybe the bootloader code in Nick's sketch handles that bug, but no luck the test bricked the mega1280 board once again. So back to looking around for a updated mega1280 bootloader that handles WDT interrupts properly.