UART Character Match Interrupt
Thanks MSchultz for the detailed response. That really helped me in getting the line break detection interrupt working properly. I was in the same situation as the original poster and was pulling my hair out.
Below are the interrupt handler and line break detection callback that worked for me. It was a little bit of a pain clearing all the flags plus reading from the ISR register so that the ISR would not re-enter. One thing I was not clear on is that there seems to be a distinction between status flags and interrupt flags. There seem to be a difference between the two.
/**
* Brief This function handles USARTx Instance interrupt request.
* Param None
* Retval None
*/
void USARTx_IRQHandler(void)
{
if ((LL_USART_IsActiveFlag_FE(USARTx_INSTANCE) || LL_USART_IsActiveFlag_LBD(USARTx_INSTANCE))
&& LL_USART_IsEnabledIT_LBD(USARTx_INSTANCE)
&& LL_USART_IsEnabledLIN(USARTx_INSTANCE)) {
/* Toss Receive Data */
LL_USART_ReceiveData8(USARTx_INSTANCE);
/* Clear ORE (Overrun Error) Flag */
LL_USART_ClearFlag_ORE(USARTx_INSTANCE);
/* Clear EOB (End of Block) Flag */
LL_USART_ClearFlag_EOB(USARTx_INSTANCE);
/* Clear FE (Frame Error) Flag */
LL_USART_ClearFlag_FE(USARTx_INSTANCE);
/* LBD flag will be cleared after reading of ISR register (done in call) */
/* Call function in charge of handling Character reception */
USART_LineBreak_Callback();
}
/**
* @brief Function called from USART IRQ Handler when LBD flag is set
* Function is in charge of reading line break received on USART RX line.
* @param None
* @retval None
*/
void USART_LineBreak_Callback(void)
{
__IO uint32_t isr_reg;
isr_reg = LL_USART_ReadReg(USARTx_INSTANCE, ISR);
if (isr_reg & LL_USART_ISR_LBDF) {
/* Toggle LED */
LL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN);
/* Clear LBD Flag */
LL_USART_ClearFlag_LBD(USARTx_INSTANCE);
}
}
All the code was based on this example:
https://github.com/STMicroelectronics/STM32CubeG0/tree/master/Projects/NUCLEO-G071RB/Examples_LL/USART/USART_Communication_Rx_IT