I am trying to accomplish a reset of the arduino using a watchdog timeout that allows it to return to the bootloader to be programmed. However the over arching objective is simply to be able to reset the device and re initiate the bootloader via serial command. A lot of the challenge with this is that I don't think I am asking the correct questions, or using the right terminology to search for it. I have an UNO running the version of optiboot shipped with Arduino 1.5. Thank you in advance to anyone that answers this.
2 Answers
Not sure what your question is?
But I sounds like you are asking how to perform a soft reset using the watchdog.
There are several methods to cause a soft reset. The quickest/simpleset that I use is;
#include <avr/wdt.h>
...
wdt_enable(WDTO_15MS); // provides a Soft Reset when connected to FDTI Port, that provides power
for(;;) {} // wait for it to reset and start over at the boot loader...
Comments
If you do not want to use the watchdog timer and your part supports it you can set the RESET bit in RST_CTRL from this thread
#define RST_SWRST_bm 0x01
#define CCP_IOREG_gc (0xD8<<0)
void force_sw_reset(void)
{
__disable_interrupt();
CCP = (uint8_t)CCP_IOREG_gc;
RST.CTRL = (uint8_t)RST_SWRST_bm
}
If you do not need to do a full reset your can jump to the reset vector, from this thread:
#define RESET_VECTOR 0
void (*ptrToFunction)(); // pointer to a function
ptrToFunction = RESET_VECTOR;
(*ptrToFunction)(); // reset!
If you want to use the watchdog timer mpflaga has the correct answer although bear in mind depending on your part the watchdog timer may or may not be enabled after the reset, see Atmels page on soft reset here. If your atmega is resetting in the bootloader when you don't expect it to this is likely to be your problem.