Reset your arduino!

In this post, we will look at two ingenious ways in which one can implement a software based reset routine for the arduino.

Reset switch
Image credits

How do we reset our arduino? There are many ways to do so. I think that the two methods discussed below are the most used and probably the best! Err, I cannot vouch for being the best options, but then you should know what options do we have afterall! The essential idea in both of the methods discussed below is to take the program counter back to address 0x0 as in the arduino uno the code is present and starts from memory address 0x0.

Option 1:

/*----------------------------------------------------------------------------*/
/* Function : arduino_reset */
/*----------------------------------------------------------------------------*/
/*!
  @ brief
  This API resets the controller by jumping to address 0

  @ details
  This API resets the controller by jumping to address 0

  @ pre-requirements
  @ param void
  @ return void
*/
static void arduino_reset ( void )
{
  asm volatile ("  jmp 0");
}/* arduino_reset */

In this method we use assembly instruction to explicitly make the program counter jump to memory address 0x0.

Option 2:

/*----------------------------------------------------------------------------*/
/*!@brief function pointer */
void ( * reset_ft) (void) = 0;

/*----------------------------------------------------------------------------*/
/* Function : arduino_reset */
/*----------------------------------------------------------------------------*/
/*!
  @ brief
  This API resets the controller by calling a Null Function Pointer

  @ details
  This API resets the controller by calling a Null Function Pointer

  @ pre-requirements
  @ param void
  @ return void
*/
static void arduino_reset ( void )
{
  reset_ft ();
}/* arduino_reset */

OK. This is more of a childish method if you do not like using assembly in your C code. What I did here is simple. I declared a function pointer reset_ft and pointed it to the memory location 0x0. So when the function pointer reset_ft() is called, it just starts executing what instructions are present at memory location 0x0 - which is nothing but the start of the code!

So, there it is. Easy peasy! Happy resetting without pulling down the reset pin! :-)