Hi everyone,
I would like to find a way to reset the board by software instructions. I think this should be possibile configuring the watchdog, but I didn't find nothing related to the Arduino Due.
The goal I want to achieve is to restart the board when some condition happens. Any way to do that will be fine for me, but I have not to touch any hardware or to trigger the reset by an external divece.
I'm new with Arduino due and your question is very interesting. I had a look of the mcu data sheet at chapter 17 (watchdog) and I tried to make it working. The first step is to avoid that the function init() inside the file variant.cpp (....\hardware\arduino\sam\variants\arduino_due_x) disable the watchdog by commenting the function WDT_disable(WDT) otherwise you'll not able to enable the watchdog later (the register REG_WDT_MR can be written only once) then in the setup() function inside the sketch I inserted the following instruction:
REG_WDT_MR = 0x0fff2fff;
In order to have the WDT activated.
Now you can use the instruction to reset the WDT:
REG_WDT_CR = 0xa5000001
If you want to reset just avoid to execute the last instruction in the main() function and after 16seconds from the last call the WDT shall reset the mcu and the sketch start again.
I hope my suggestion can be a good starting point.
Kind Regards.
P.s.: remember to remove the comments that you inserted in the variant.cpp file when you don't need the WDT inside your sketch.
void Software_Reset() {
//============================================================================================
// führt ein Reset des Arduino DUE aus...
//
// Parameter: keine
// Rueckgabe: keine
//============================================================================================
const int RSTC_KEY = 0xA5;
RSTC->RSTC_CR = RSTC_CR_KEY(RSTC_KEY) | RSTC_CR_PROCRST | RSTC_CR_PERRST;
while (true);
}
I'm new with Arduino due and your question is very interesting. I had a look of the mcu data sheet at chapter 17 (watchdog) and I tried to make it working. The first step is to avoid that the function init() inside the file variant.cpp (....\hardware\arduino\sam\variants\arduino_due_x) disable the watchdog by commenting the function WDT_disable(WDT) otherwise you'll not able to enable the watchdog later (the register REG_WDT_MR can be written only once) then in the setup() function inside the sketch I inserted the following instruction:
REG_WDT_MR = 0x0fff2fff;
In order to have the WDT activated.
Now you can use the instruction to reset the WDT:
REG_WDT_CR = 0xa5000001
If you want to reset just avoid to execute the last instruction in the main() function and after 16seconds from the last call the WDT shall reset the mcu and the sketch start again.
I hope my suggestion can be a good starting point.
Kind Regards.
P.s.: remember to remove the comments that you inserted in the variant.cpp file when you don't need the WDT inside your sketch.
That works very good in Arduino Due! Thank you xD
But can i change the watchdog from 16seconds, to 3 seconds or 2 seconds???
In particular, how they shift the __WDP_MS definition by 16 bits.
In this older thread, they use "REG_WDT_MR = 0x0fff2fff", which sets the highest 16 bits to 0x0fff (4095), which I believe is the highest timer length possible (4095 / 256 = 15.996, almost 16 seconds).