Monday, December 23, 2013

Good to knows - 4

Using the watchdog to reset the mcu if something goes wrong:


void setup ()
  Serial.begin (115200);
  Serial.println ("Restarted.");
  wdt_enable (WDTO_1S);  // reset after one second, if no "pat the dog" received
 }  // end of setup

void loop ()
  Serial.println ("Entered loop ...");
  wdt_reset ();  // give me another second to do stuff (pat the dog)
  while (true) ;   // oops, went into a loop
}  // end of loop

This code comes from

Obviously this can be used to trigger a restart when you detect an error (if error --> while(1){})

No comments:

Post a Comment