Then, all you had to do was call the method software_Reboot and the Arduino would reset. This was perfect and exactly what I am looking for. However, this does not work on the Due. First of all, it appears that avr/wdt.h does not exist for the Due.
Anybody have a quick and easy way to reset the Due from code, similar to above, but that works for the Due?
More likely, you need to fix the real problem with your code.
PaulS, how can you make that snide remark when you have no clue why I would need to do a reset? There are some good reasons why one might need to do a reset even with perfect code.
Not sure if this helps, but it helped me. I was looking for a way to properly reset the Due without using a pin, the WDT, or the jump to 0. After lots of searching the web and pouring over the SAM datasheet, the following is code should will work on any ARMv7-M architecture such as the SAM3X used on the DUE.
Add these defines to the start of your code;
//Defines so the device can do a self reset
#define SYSRESETREQ (1<<2)
#define VECTKEY (0x05fa0000UL)
#define VECTKEY_MASK (0x0000ffffUL)
#define AIRCR (*(uint32_t*)0xe000ed0cUL) // fixed arch-defined address
#define REQUEST_EXTERNAL_RESET (AIRCR=(AIRCR&VECTKEY_MASK)|VECTKEY|SYSRESETREQ)
The SYSRESETREQ is bit 2 in the AIRCR register and needs to be set to request a reset. Before this can be done, 0x05FA needs to be put into AIRCR register VECTKEY bits16:31 or the write to SYSRESETREQ will be ignored.
The final line simply puts it all together to create the actual command to reset REQUEST_EXTERNAL_RESET and could be renamed as you desire.
Use this command when you want to reset the DUE.
REQUEST_EXTERNAL_RESET;
This worked for me, but I did need to add some delay (I used 1000mS) after a Serial.println("Something to print"); as it reset before the data got out to the terminal.
I've found a dead simple method for resetting the Arudino Due:
RSTC->RSTC_CR = 0xA5000005; // Reset processor and internal peripherals
Seriously, that's it.
If you want the external reset pin to also get pulled low (e.g. to reset external peripherals, like jot4p's ethernet shield) just change it to:
RSTC->RSTC_MR = 0xA5000801; // Set RST pin to go low for 256 clock cycles on reset
RSTC->RSTC_CR = 0xA5000013; // Reset processor, internal peripherals, and pull external RST pin low.
The relevant section of the datasheet is pages 223-233.
I realise this is an old topic but it's #1 on google for queries on how to software reset Due.
The atmel asf (the SDK atmel/microchip provide for the sam3x8e), which Arduino uses and is therefore usable in your own sketches, provides a simple software reset function:-
slippyr4:
I realise this is an old topic but it's #1 on google for queries on how to software reset Due.
The atmel asf (the SDK atmel/microchip provide for the sam3x8e), which Arduino uses and is therefore usable in your own sketches, provides a simple software reset function:-