AnsweredAssumed Answered

Can an interrupt be triggered when the flag bit is set and then the interrupt enable bit is set?

Question asked by bao.jianyi on May 29, 2015
Latest reply on May 29, 2015 by bao.jianyi
STM32L051xx: 

I am using the interrupt mode for UART2 Rx. Normally the interrupt is enabled at the beginning, so that Rx interrupt could be triggered once a new byte is received.

However sometimes in the program I need to disable the interrupt, do something and enable it again, like the following:

  HAL_NVIC_DisableIRQ(USART2_IRQn);
  
  //do something where UART interrupt should be avoided, for example when you modify some global variables that are also used in the interrupt IRQ handler.
  //the execution time is very short.
  
  HAL_NVIC_EnableIRQ(USART2_IRQn);
  
  So it is possible a new byte arrives and RXNE bit is set when the interrupt is disabled, and the interrupt will not be triggered. Will it be triggered immediately again just after the interrupt is enabled again? If not, the new byte will be lost and even an overrun error will happen.
  
  Thanks

Outcomes