Go Down

Topic: Watchdog Trouble (Read 1 time) previous topic - next topic

dc42

Have you tried disabling the watchdog at the start of setup(), using the code I gave in the thread I linked to in an earlier post?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Loic85

Yes, I do (see the code below).
:smiley-eek: I must confess you that there is something that escapes me. Indifferently of boot, if I write in the watchdog registers the good values, the ┬ÁP must be done a reset. Why doesn't it done ?

Code: [Select]
#include <avr/wdt.h>

void setup()
{
  Serial.begin(9600);

 // Turn off watchdog timer  <--- recopy to your post
 cli();
 wdt_reset();
 MCUSR = 0;    // clear watchdog reset flag
 WDTCSR |= (1 << WDCE) | (1 << WDE);
 WDTCSR = 0x00;
 sei();
  // set the watchdog to 8s
  wdt_reset();  
 // disable all interrupts
 cli();
 wdt_reset();
 MCUSR &= ~(1<<WDRF);
 WDTCSR |= (1 << WDCE) | (1 << WDE);
 WDTCSR = (1 << WDE) | (1 << WDP3) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0);  // 8s
 // enable all interrupts
 sei();
}
void loop()
{
   Serial.println("I am in the loop");
   while(1) {
      // to have the reset !!!
      Serial.println(millis());
   }
}

Loic85

Sorry for my insistence, but I am always blocking  =(
Is there any body who arrive to do worked a reset watchog on arduino mega ? If yes, please could you give me a simple example.
Thanks in advance.

Nick Gammon

What's all the mucking around with registers? Here is an example that works on a Uno:

Code: [Select]

#include <avr/wdt.h>

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

void loop ()
  {
   
  Serial.println ("Entered loop ...");
 
  Serial.println ("Point A");
  delay (500);
  Serial.println ("Point B");
  delay (400);
 
  wdt_reset();  // give me another second to do stuff (pat the dog)
 
  Serial.println ("Point C");
  delay (500);
  Serial.println ("Point D");
  delay (400);
 
  while (true) ;   // ohno!, went into a loop
     
  }  // end of loop


I tested that on my Mega and it didn't work. I suspect there is a problem with the bootloader and then watchdog timer. There are some known problems with the watchdog timer and the bootloader.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

That sketch bricks my Mega in a rather annoying way. You can recover by re-uploading the bootloader but there is clearly something wrong.

You can also recover by:


  • Open a sketch that doesn't use the watchdog (eg. Blink)

  • Unplug the USB (so the board is powered off)

  • Hold down the reset button with one hand

  • Keeping it held down, plug in the USB

  • Start uploading

  • Release the reset button a moment or two after it says "uploading"

  • With luck, the new sketch will be uploaded


Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see:

Code: [Select]

Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D


So the watchdog works then. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Loic85

:) I am happy to see that the watchdog can work with mega board.
I followed each step that you said but the program stops after "Point D".
I think that my problem is with BOOTRST fuse.
Quote
I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see:

I didn't find where I can unset the BOOTRST fuse. How do you do that ?
Thanks very much for your help.

Nick Gammon

I uploaded the .hex file with my "hex file uploader" described here:

http://www.gammon.com.au/forum/?id=11638

A side-effect is it clears the BOOTRST fuse if it is uploading a "normal" program (not a bootloader).

However if you have a programmer (such as USBISP or similar) you can use avrdude to change fuses.

Something like this:

Code: [Select]

avrdude -c usbtiny -p m2560 -U hfuse:w:0xD9:m


Better check with http://www.engbedded.com/fusecalc before changing fuses. Get that wrong and you might not be able to program it again without using a high-voltage programmer (next to impossible with a surface-mounted chip).

The alternative is to ask around for a bootloader that doesn't have this problem. I thought mine didn't but was wrong. You still need a programmer to install the new bootloader, but you can use a spare Uno for that. (See the posts about Arduino as ISP).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Loic85

Thank you very much for your answer and a big cheer for your project, it is very interesting.
Actually, I haven't the equipment to work the reset watchdog on arduino mega.
I keep this post and I will buy the programmer or a SD card reader to use your project with my uno.

:smiley-roll: A last idea comes me, does it exist an other board with equivalent ATMEL as mega, which the reset watchdog  works with the default bootloader ?

dc42

A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Loic85

yes, I already saw that, but I don't have equipment to flash my board. So, I will buy the programmer and as well as placing an order, I want to know, if it exists a board equivalent to arduino mega which the reset watchdog works by default (with factory parameters). Do you know if is it exist ?

Nick Gammon

The bootloader is software. It's easy enough to replace it. Personally I don't know of a Mega-equivalent with the correct bootloader on it.

Quote
A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders.


Yes, well I downloaded one that claimed to have fixed the watchdog problem, but it didn't.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Loic85

Thanks for your answer, I bought the programmer and I hate to receive it to flash the bootloader.

Go Up