Can't get Watchdog on ATMega644 to reset the M644

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I want to create a software reset by enabling the watchdog and wait until the watchdog creates a reset. But the reset doesn't happen at all! I can't seem to find the problem and have studied the datasheet several times. Here is my code:

/* DISABLE INTERRUPTS */
uP__Disable_Interrupts;

/* ENABLE THE WATCHDOG */
WDTCSR=(1<<WDCE) | (1<<WDE);
WDTCSR=0x08;

/* WAIT FOR RESET TO OCCUR */
while (1)
{
}

Any help or suggestions?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks OK. Check the generated code to make sure that the timing requirement is met.

How are you detecting whether the reset happens or not?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply,

Code seems OK, I post it here :

/* DISABLE INTERRUPTS */
      	uP__Disable_Interrupts;
    175c:	f8 94       	cli
      	
      /* ENABLE THE WATCHDOG */
      	WDTCSR=(1<<WDCE) | (1<<WDE);
    175e:	28 e1       	ldi	r18, 0x18	; 24
    1760:	20 93 60 00 	sts	0x0060, r18
      	WDTCSR=0x08;
    1764:	88 e0       	ldi	r24, 0x08	; 8
    1766:	80 93 60 00 	sts	0x0060, r24
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, on your comment:

Quote:
How are you detecting whether the reset happens or not?

If I take out the while loop, the uP continues to run and to communicate with the PC, with the while loop inserted I loose communications with the uP.

I assume it should work, it did work with a ATMega128 and then I switch over to the ATMega644

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Curious, why aren't you using the code from ?

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I will try using the code from wdt.h, just thought that it should be simple and easy to do it myself.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Curious, why aren't you using the code from ?

Perhaps the OP is one of the unwashed masses that uses a different compiler other than the one that has ? ;)

(There must have been a hint in the posted code fragment.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> Perhaps the OP is one of the unwashed masses that uses a
> different compiler other than the one that has ?

Given the disassembly listing he's been posting, it clearly
identified him as a GNU tools user... I wouldn't have asked
otherwise.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Found the problem!

I cleared the MCUSR register then the WDE bit (disable watchdog) in my startup routine in my application program, as the datasheet suggest, because the watchdog will still be enabled after reset. But it should have been in my bootloader, as the bootloader gets first executed from startup after power-up/reset.

So what happened is, when I tell the Mega644 to reset, it did reset but when starting the bootloader, the watchdog is still enabled, and I took too long to disable the watchdog, so the Mega644 kept resetting because the watchdog is still enabled.

So I just moved the code to my bootloader .... problem solved! :D

Jacques