cancel
Showing results for 
Search instead for 
Did you mean: 

A confused problem about WWDG_IRQHandler

FLast.2
Associate II
Posted on September 03, 2016 at 15:52

Hi, i'm studying stm32f407, but there is a problem puzzling methose days. It's about the WWDG.

I just want to test the function of WWDG, so in my function which has been wrote to initialize the WWDG, i enable the WWDG early wakeup interrupt, the function seems as:

void WWDG_Init(u8 tr,u8 wr,u32 fprer)
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
WWDG_CNT=tr&WWDG_CNT;
WWDG_SetPrescaler(fprer);
WWDG_SetWindowValue(wr);
WWDG_Enable(WWDG_CNT);
NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
WWDG_ClearFlag();
WWDG_EnableIT();
}

And in theWWDG_IRQHandler function, the code is:

void WWDG_IRQHandler(void)
{
WWDG_SetCounter(WWDG_CNT);
WWDG_ClearFlag();
LED1=!LED1;
}

Where the LED1 linking a GPIO pin. (P.S. The main function has not been posted)

The problem com

es from theWWDG_IRQHandler function. When i download the code to my board, the led1 blinks very well,which exactly what i'm lookingfor.

But when i exchange the last two lines, namely:

void WWDG_IRQHandler(void)
{
WWDG_SetCounter(WWDG_CNT);
LED1=!LED1;
WWDG_ClearFlag();
}

Then the LED1 won't be blink any more.

I don't know why i just exchange the last two lines will cause the problem, it seems very puzzling.

Can any one help me?

Best regards.

2 REPLIES 2
matic
Associate III
Posted on September 04, 2016 at 08:00

I think the problem is here... Flag should never be cleared at the end of interrupt routine as a last operation. It should be at the beginning or somewhere in between.

I can't explain exactly why. When flag is cleared in a peripheral register, this ''erased state'' still needs some time to reach NVIC controller. When program leaves the interrupt routine, NVIC always checks, if any interrupt is on pending. Although you cleared the flag in peripheral just before that, NVIC still see it as a pending and then the program goes directly back to interrupt. This means, the interrupt routine is rolling constantly.

FLast.2
Associate II
Posted on September 04, 2016 at 09:32

Hi, obid, thank you very much.

Best regards.