Know if a watchdog reset has tripped - SOLVED

I'm using the Adafruit_SleepyDog library, and would be nice at powerup to know if a watchdog reset has occoured.

It's possible?

Enrico Michieletti
Enrico Michieletti
95
| 3 1 2
Asked on 12/25/20, 7:59 PM
1
vote
1520 Views

I answer to my own question:

The same library that check the watchdog can read the MCU registry RCAUSE register..

[code]

#include <Adafruit_SleepyDog.h>

 

  uint8_t resetCause = 0;

  SerialUSB.print(F("Last reboot reason : "));
  resetCause = Watchdog.resetCause();
  if (bitRead(resetCause,0)) {  //Power-on-reset
     SerialUSB.println(F("Power-on-reset"));
  } else if (bitRead(resetCause,1)) {  //Brown-out-detect BOD12
     SerialUSB.println(F("Brown-out-detect BOD12"));
  } else if (bitRead(resetCause,2)) {  //Brown-out-detect BOD33
     SerialUSB.println(F("Brown-out-detect BOD33"));
  } else if (bitRead(resetCause,4)) {  //External reset
     SerialUSB.println(F("External reset"));
  } else if (bitRead(resetCause,5)) {  //Watchdog reset
     SerialUSB.println(F("Watchdog reset"));
  } else if (bitRead(resetCause,6)) {  //System reset
     SerialUSB.println(F("System reset"));
  }

 Little update, seem that the function not give the correct value as i read always as reason a "system reset". Need to investigate why.

Enrico Michieletti
Enrico Michieletti
95
| 3 1 2
Answered on 1/2/21, 2:52 PM
1
vote

Did you get this sorted? What is the solution?

Aaron
on 1/18/21, 3:32 PM

Hi @Aaron, the solution is the Watchdog.resetCause(). But i'm not sure that it works as it should as by now i've always seen "System reset" as a reboot cause... I've checked the Adafruit_SleepyDog.h code ad it check the correct register, so i need to made some more tests.

Enrico Michieletti
on 1/18/21, 6:04 PM

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

63 follower(s)

Stats

Asked: 12/25/20, 7:59 PM
Seen: 1520 times
Last updated: 1/4/21, 1:24 AM