cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt flag is set, but interrupt is not entered

AHass.1
Associate II

Dear community,

once again I am asking for your kind help. I want to implement a simple timer interrupt as a time basis on my STM32F407. I configured Timer11 and it seems to count as I expected (as far as my debugger can tell me). When the counter hits the first overflow, the "update interrupt flag" UIF from the TIM11_SR register is set, but the ISR is not executed. I already searched for a global interrupt flag that I might need to set, but as far as my research told me there is no global interrupt enable, but maybe I am wrong on that.

My initialization code and the ISR are mentioned below.

static unsigned int counter = 0;
 
void timerInit(void)
{
	RCC->CFGR		|=  (0b1111 << RCC_CFGR_HPRE_Pos);		// only for debugging
	RCC->CFGR		&= ~(0b11 << RCC_CFGR_SW_Pos);
	RCC->CFGR 		|= (0b01 << RCC_CFGR_SW_Pos);			// choose external crystal osc as system clock
	RCC->APB2ENR 	|= (1 << RCC_APB2ENR_TIM11EN_Pos);		// Enable Timer 9 clock source
	TIM11->DIER		|= (1 << TIM_DIER_UIE_Pos);				// Enable Interrupt
	TIM11->PSC		|= 1;									// prescaler: Counter clock: f_ck_psc/(PSC + 1) = 4 MHz @ 8 MHz System clock, no prescalers
	TIM11->ARR		|= 40000;								// 4 MHz / 40000 = 100 Hz => overflow every 10 ms
	TIM11->CR1		|= (1 << TIM_CR1_URS_Pos)				// interrupt only on counter overflow
					|  (1 << TIM_CR1_CEN_Pos);				// Enable Timer
}
 
 
void TIM11_DAC_IRQHandler(void)
{
	if (counter <= 100)
		counter++;
	else
	{
		toggle_LED(LED_D3);
		counter = 0;
	}
}

Thank you in advance for any help!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You need to enable the corresponding NVIC interrupt.

NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);

Also, looks like you might have ported code from a different processor as well, since the interrupt should be named TIM1_TRG_COM_TIM11_IRQHandler. edit: actually I have no idea where you got this. "TIM11_DAC_IRQHandler" has zero hits on github.

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h

Also you'll need to clear the flag in the interrupt, otherwise it'll just keep triggering.

Also the ARR is off by one. If you want a divider of 40000, set the value to 39999.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

You need to enable the corresponding NVIC interrupt.

NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);

Also, looks like you might have ported code from a different processor as well, since the interrupt should be named TIM1_TRG_COM_TIM11_IRQHandler. edit: actually I have no idea where you got this. "TIM11_DAC_IRQHandler" has zero hits on github.

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h

Also you'll need to clear the flag in the interrupt, otherwise it'll just keep triggering.

Also the ARR is off by one. If you want a divider of 40000, set the value to 39999.

If you feel a post has answered your question, please click "Accept as Solution".
AHass.1
Associate II

Late reply, but all of your points where right.

Thank you!