cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt enabling/disabling

xhpohanka
Associate
Posted on March 18, 2013 at 19:15

Hello,

please look at following interrupt routines for capture/compare and uart receive

void TIM1_CC_IRQHandler(void)

{

uint32_t break_time, mab_time;

TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);

break_time = TIM_GetCapture2(TIM1);

mab_time = TIM_GetCapture1(TIM1) - break_time;

/* use some tolerance for times */

if (break_time > 80 && break_time < 10e3 && mab_time > 😎 {

start_flag = 1;

TIM_ITConfig(TIM1, TIM_IT_CC1, DISABLE);

} else {

start_flag = 0;

}

}

void USART2_IRQHandler(void)

{

uint8_t rx_byte;

int16_t fe_flag;

USART_ClearITPendingBit(USART2, USART_IT_RXNE);

fe_flag = USART_GetFlagStatus(USART2, USART_FLAG_FE);

rx_byte = USART_ReceiveData(USART2); /* also clears FE flag */

if (fe_flag) {

TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);

return;

}

if (start_flag)

byte_count = 0;

byte_count++;

}

CC and UART input are connected together and CC is measuring BREAK condition (low for 80us and more). When BREAK is detected UART receives a (constant) number of bytes. As I know that another BREAK will occur ''after some time'' I would like to disable CC interrupt. It can be enabled again when framing error arises. The theory is nice but this code works only when I'm not disabling the interrupt. 

I have checked it with a scope (toggling a pin in interrupts) and I see what I'm expecting: the FE flag is set and interrupt fired during the BREAK. I see that there is enough time before edge which fires the CC interrupt. But even if I reenable the CC interrupt it is not fired anymore. I have also tried handle the interrupts through NVIC, but the situation is the same.

Do please someone see an error in my expectations?

regards

Jan

#interrupt
5 REPLIES 5
Posted on March 19, 2013 at 10:50

Looks reasonable, but we don't see the rest of your code.

Try to produce a minimal but complete compilable example which exhibits the problem and post it here.

JW
jpeacock2399
Associate II
Posted on March 19, 2013 at 14:51

Kinda obvious, but is start_flag declared as volatile?

  Jack Peacock
Posted on March 20, 2013 at 11:18

> Kinda obvious, but is start_flag declared as volatile?

Even if it wouldn't be, based on the snippet of code we see, it shouldn't prevent reenabling the timer interrupt... or did I overlook anything?

JW

xhpohanka
Associate
Posted on March 20, 2013 at 14:04

Hi and thank you for answers.

I will prepare it some minimal example when I have a time to do that. Whole source (in the version without disabling/enabling interrupt) can be found on github (

https://github.com/xhpohanka/dmx_dimmer

)

As I said before, the interrupt is the only issue. When I do not disable it in CC isr everything works. I know also that there are different approaches how to do that like use only USART interrupt and FE flag etc. But I'd like to know why this specific code does not work

regards

Jan
Posted on March 20, 2013 at 16:10

Btw., how do you know that

> even if I reenable the CC interrupt it is not fired anymore

?

JW