Jump to content

Recommended Posts

converted the watchdog example from Tivaware into Energia.

it should explain itself...

I tested this with the connected launchpad TM4C1294


5 blinks, resets itself, 5 blinks, on and on....

6.11.2015 Watchdog example

#define LED RED_LED

#include <stdint.h>
#include <stdbool.h>

#include "driverlib/sysctl.h"
#include "driverlib/watchdog.h"

unsigned long oldmillis;
unsigned int  timeout;
void setup() {                
  pinMode(LED, OUTPUT);     

// the loop routine runs over and over again forever:
void loop() {
  if (millis()>(oldmillis+500)){

    digitalWrite(LED, HIGH);   
    digitalWrite(LED, LOW); 
    WatchdogReloadSet(WATCHDOG0_BASE,120000000);    //feed the dog, food for a second ;-)
 // simulated software crash: dog will not be fed any longer, causing a reset
    if (timeout>5){

Share this post

Link to post
Share on other sites

Answering a different thread, I just now discovered this thread. http://forum.43oh.com/topic/9240-watchdog-timer-for-tiva-tm4c1294ncpdt/


Below is a bit more extensive example of how to use the watchdog timer to reset the system using interrupts. The idea is that when you press USR_SW1 once, the watchdog will be starved and a system reset is triggered:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/watchdog.h"
#include "driverlib/rom_map.h"
#include "driverlib/rom.h"

uint8_t feedWatchdog = true;
uint8_t ledState = true;
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 100;   // the debounce time; increase if the output flickers
int lastButtonState = HIGH; // the previous reading from the input pin

void setup()
  digitalWrite(GREEN_LED, HIGH);

  // Enable the watchdog peripheral
  // Set timeout of watchdog to 2 sec
  MAP_WatchdogReloadSet(WATCHDOG0_BASE, MAP_SysCtlClockGet() * 2);
  // Reset when watchdog expires
  // Register the watchdog interrupt handler
  WatchdogIntRegister(WATCHDOG0_BASE, &WatchdogIntHandler);
  // Enable the watchdog
  // Get and print the reset cause
  if(SysCtlResetCauseGet() & SYSCTL_CAUSE_WDOG0) {
    Serial.println("WatchDog Reset");
  }else if(SysCtlResetCauseGet() & SYSCTL_CAUSE_EXT) {
    Serial.println("External reset");

void loop()
  // Read the button that triggers starving the Watchdog
  int reading = digitalRead(PUSH1);

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  if (((millis() - lastDebounceTime) > debounceDelay) && lastButtonState == LOW) {
    // If the button has been low for longer than the debounce time, starve the Watchdog.
    feedWatchdog = false;
  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState = reading;

void WatchdogIntHandler(void)
    // If we have been told to stop feeding the watchdog, return immediately
    // without clearing the interrupt.  This will cause the system to reset
    // next time the watchdog interrupt fires.

    // Clear the watchdog interrupt.
    digitalWrite(GREEN_LED, ledState);
    ledState = !ledState;

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...