Watchdog Timer ARM Arduino DUE Board IDE 1.8.9

I have an Arduino Due board which is used for running a test on a car.
The Arduino is connected to an external touchscreen display.
Every now and then, the touchscreen freezes and the connection between Arduino and touchscreen is interrupted. I want to fix this issue by implementing a watchdog timer, which resets the Arduino after it detects no response from the Arduino for 2s.

I first tried including <avr/wdt.h>, however since Due uses ARM Microcontroller and not AVR, I am lost at what to do.
For now I have tried writing following variations: yet, I have trouble with the void watchdogSetup()

My question: how can I implement watchdog into my script?

Below is the watchdog Code that I have right now…

int watchdogTime=2000;

void watchdogSetup() {
}

void setup() {
delay(200);
watchdogEnable(watchdogTime);
}

void loop() {
watchdogReset();
}

I have the Arduino due connected to a touchscreen display EA eDIPTFT43-A in the car, to show several factors while driving experiments.

Every now and then, the touchscreen display will freeze and arduino does not work. I have to switch off and on the power supply for both to work again.

I have tried including watchdog but that doesn't help.

Does anybody else have this issue or have an idea how to fix this?

So this project is in a car? Powered by the car? Can we see a schematic?

Your 3 separate questions about the same subject posted in 3 different forum sections have been move d and merged here

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

The best solution would be to fix the freezing issue. However, if you need to trigger a watchdog reset, the sketch below will do that:

#define WDT_KEY (0xA5)
/********************************************************************************
  extern "C" void _watchdogDefaultSetup (void) { WDT_Disable (WDT); }

  void watchdogSetup (void) __attribute__ ((weak, alias("_watchdogDefaultSetup")));
*********************************************************************************/

/*This function is called from init(). If the user does not provide
  this function, then the default action is to disable watchdog.
  This function has to be overriden, otherwise watchdog won't work !! */

void watchdogSetup(void) {
  /*** watchdogDisable (); ***/
}

//void watchdogDefaultSetup (void) { }

//void watchdogSetup(void) { watchdogDefaultSetup ();}

void setup()
{
  // Enable watchdog.
  WDT->WDT_MR = WDT_MR_WDD(0xFFF) |
                WDT_MR_WDFIEN |  //  Triggers an interrupt or WDT_MR_WDRSTEN to trigger a Reset
                WDT_MR_WDV(256 * 2); // Watchdog triggers a reset or an interrupt after 2 seconds if underflow
  // 2 seconds equal 84000000 * 2 = 168000000 clock cycles
  /* Slow clock is running at 32.768 kHz
    watchdog frequency is therefore 32768 / 128 = 256 Hz
    WDV holds the periode in 256 th of seconds  */
  NVIC_EnableIRQ(WDT_IRQn);

  Serial.begin(250000);
  uint32_t status = (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos /*8*/; // Get status from the last Reset
  Serial.print("RSTTYP = 0b"); Serial.println(status, BIN);  // Should be 0b010 after first watchdog reset

}

void loop()
{

  //Restart watchdog
  WDT->WDT_CR = WDT_CR_KEY(WDT_KEY)
                | WDT_CR_WDRSTT;

  Serial.println("Enter the main loop : Restart watchdog");
  GPBR->SYS_GPBR[0] += 1;
  Serial.print("GPBR = "); Serial.println(GPBR->SYS_GPBR[0]);
  delay(500);

  while (true)
  {
    Serial.println("the software becomes trapped in a deadlock !");
    delay(500);
    /* If the software becomes trapped in a deadlock,
       watchdog triggers a reset or an interrupt. if there is a Reset, the software restarts with stored values
       in General Purpose Back up Registers*/
  }
}
void WDT_Handler(void)
{
  /* Clear status bit to acknowledge interrupt by dummy read. */
  WDT->WDT_SR; // Clear status register

  printf("help! in WDT\n");
}

groundFungus:
So this project is in a car? Powered by the car? Can we see a schematic?

the arduino and touchscreen are powered by a power supply which in turn can be turned on/off when the car is on (ignition not need, just key in slot)

ard_newbie:
/*This function is called from init(). If the user does not provide
this function, then the default action is to disable watchdog.
This function has to be overriden, otherwise watchdog won't work !! */

this init() function, is that a function from a specific library? in the rest of the code that you posted, it does not appear again...

hi folks!

i have an arduino connected to an external display...
i have watchdog implemented in my arduino. what i want to achieve is the following:

if watchdog resetted the mcu, i also want the arduino to reset the display

i have a function which resets the display. my dilemma is how to connect watchdog resetting the mcu with arduino also resetting the display

i was thinking of an if loop, but i am unsure on how to check if the mcu was resetted by the watchdog

anybody have an idea?

I’m not sure what an if loop is, but if resetting the processor resets the display, won’t the watchdog reset do that too?

I have no idea what you are asking.

Is your watchdog hardware or software?
Which Arduino?
Which display?
How connected?

Show your code and schematic (please, NOT a pretty Fritzing drawing).
Read the "How to use this forum" sticky.

duplicate post

TheMemberFormerlyKnownAsAWOL:
I'm not sure what an if loop is, but if resetting the processor resets the display, won't the watchdog reset do that too?

my idea with the if loop summarized:

IF watchdog reset mcu
{
touchscreen_reset(); // function which orders arduino to reset the touchscreen
}

the part where I am stuck on is, how to write the code for testing whether watchdog has reset the mcu.

SteveMann:
I have no idea what you are asking.

Is your watchdog hardware or software?
Which Arduino?
Which display?
How connected?

Show your code and schematic (please, NOT a pretty Fritzing drawing).
Read the "How to use this forum" sticky.

yes sorry, I completely forgot to add the details!

the watchdog in the arduino DUE is hardware. the display connected is the EA eDIPTFT43-A from Eletronics Assembly.

arduino and display are connected through pins 8 (PWM) and RESET pin 5 respectively.

I have a function which calls a reset for the display. this function i want called everytime watchdog resets the arduino mcu. my dilemma is how I call this function specifically only when watchdog resets the arduino. I was thinking of using an IF statement, but i am having problems on how to get the true statement so: IF watchdog resets the mcu THEN call function to reset display

@needhelp123456

You were warned about cross posting so please take the next 7 days to read the links below.

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

needhelp123456:
I have an Arduino Due board which is used for running a test on a car.
The Arduino is connected to an external touchscreen display.
Every now and then, the touchscreen freezes and the connection between Arduino and touchscreen is interrupted. I want to fix this issue by implementing a watchdog timer, which resets the Arduino after it detects no response from the Arduino for 2s.

I first tried including <avr/wdt.h>, however since Due uses ARM Microcontroller and not AVR, I am lost at what to do.
For now I have tried writing following variations: yet, I have trouble with the void watchdogSetup()

My question: how can I implement watchdog into my script epayitonline

Below is the watchdog Code that I have right now…

int watchdogTime=2000;

void watchdogSetup() {
}

void setup() {
delay(200);
watchdogEnable(watchdogTime);
}

void loop() {
watchdogReset();
}

Did you found any good answer…