AnsweredAssumed Answered

Interrupt enabling/disabling

Question asked by pohanka.jan on Mar 18, 2013
Latest reply on Mar 20, 2013 by waclawek.jan
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 > 8) {
          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

Outcomes