I'm building a data logger using Seeeduino Stalker V2.3 and a GPRS V2.0 shield. It will be functioning at a remote location for very long(years, hopefully), so I don't want it to freeze up in the first week, and just stop working. I'm storing all data on an SD card, and I'm making it accessible via SMS, so an occasional reset won't hurt.
I want to use the built-in watchdog timer to reset it if the program freezes. As far as I understand it should work as follows (using the avr/wdt.h library):
You activate it with the "wdt_enable(CONST)" command in the setup. I used "wdt_enable(WDTO_8S)" for an 8 second watchdog timer.
After this the watchdog should regularly petted with the "wdt_reset()" command.
If the watchdog isn't petted within the specified time(in my case: 8 seconds), it bites, and resets the Stalker. This reset should have the same effect as pressing the reset button on the controller itself, causing the program to run from setup().
IMPORTANT: If my understanding of the watchdog timer is wrong, please correct it.
So if you look at my attached code, you will see this is what I have done. I activated the timer at the very top of my setup(), and I reset it in the function "stateTransitionMonitor", which is called at the top of loop(). Please note that I use a state machine architecture, and that I initialize the program to an error state only to demonstrate my problem. The idea is that it resets either when the error state is reached, or if it is stuck in any state other than _IDLE_ for too long.
If I run my code, the following happens:
The program gets through setup() fine, printing "Entering loop..." at it's end. Then it goes into stateTransitionMonitor(), where it prints "Watchdog missed" and "ERROR" for 8 seconds, just like it should.
Then it stops. Indefinitely. Which is wrong, right? It should be starting with setup() again, printing "Entering loop...", and repeating the events that happened just before.
So what's going wrong? How can I make it reset?
I googled this, and found slightly similar cases, but most of them had different hardware and solved their problems by burning a new bootloader. As an only slightly experienced Arduino enthusiast, I thought it might be wise to seek the forums advice before messing with the bootloader.