Detect lockup by capture stack before watchdog reset

Hi all,
I'm running into trouble because my AT1284p stopps working after about 1,5 -2 days. I did allready a lot of debugging, but can't get closer to the error.

Now I've read an very interesting article about saving the stack address during the watchdog reset.

I like the idea of the solution in the link, but my problem is, that I can't include the library shown in the article above because im using the ISR(WDT_vect) already for a kind of extended watchdog. My ISR contains a counter to extend the watchdog time from 8s to about 45min. Also i use it to make a kind of calibration between the slow clock in powerdown mode and the normal 8Mhz clock to keep the time correct.

I'm looking for an easy way of saving the stack address just before the watchdog is reseting. I don't need the ability to store extra informations or the last 10 stack addresses. One single stack of the last wtd reset is far ok.

Does anyone of you have done a more simple variant of this? This might make it easier for me to integrate it in my programm.

Thank you so far in advanced!

'SP' is the stack pointer register. Use that value as an address to move some bytes from the stack to EEPROM at the beginning of your Watchdog interrupt handler. In setup(), after you have initialized the Serial output, dump that portion of EEPROM to Serial.

WARNING: You can only write into EEPROM 100,000 times before it wears out. At 8 second intervals that is a little over 220 days so don't leave this code in after you solve the problem!

  // Save the stack contents in EEPROM
  uint8_t *stack = (uint8_t *)SP;
  for (int i=0; i < 16; i++)
    EEPROM.write(i, stack[i]);
  // Dump the saved stack bytes
  for (int i=0; i < 16; i++)
  {
    Serial.print(EEPROM.read(i), HEX);
    Serial.print(' ');
  }
  Serial.println();

I have used FRAM and each function stores a number in a sequential location. I keep the pointer in the first few bytes. It has no R/W limit ind is much faster teh EEPROM. I hope this can help.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.