cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L052R8 Watchdog Timer Issue

snehakarthik
Associate

I have configured the watchdog for the maximum duration possible, i.e, 1.7 sec. 

void watchdog_init(void)
{
CLK_ICKCR |= CLK_ICKR_LSION;
IWDG_KR = 0x55; 
IWDG_PR = 6; 
IWDG_RLR = 0xFF;
IWDG_KR = 0xCC; 
}

But it seems to be resetting in around 26 - 28 ms. I have also checked this timing with an oscilloscope by toggling a led. 

watchdog_init();
do {
LED5_TOGGLE();
printf("Test!\n");
delay(516);
} while(1);
  
What do you think is the cause for this issue? How is it possible to fix this? 
1 REPLY 1
AA1
Senior III

As explained in RM, the first step must be enable the watchdog. As is, the watchdog is using the reset values.

Use this code:

void watchdog_init(void)
{
CLK_ICKCR |= CLK_ICKR_LSION;
IWDG_KR = 0xCC; // enable
IWDG_KR = 0x55; // write access
IWDG_PR = 6;
IWDG_RLR = 0xFF;
IWDG_KR = 0xAA; // refresh
}

,