cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474 - UART interrupts keep firing when they should not be enabled

Richard Tarbell_2
Associate II

I am using USART2 on the G474 processor, and I only want the TXE and RXNE interrupts to fire. To do so, I wrote the following:

	//Enable/set the TXE and RXNE interrupt bits
	__HAL_USART_ENABLE_IT(&husart2, USART_IT_TXE);
	__HAL_USART_ENABLE_IT(&husart2, USART_IT_RXNE);
	
	//Disable all other USART interrupts:
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_RXFF);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_TXFE);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_RXFT);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_TXFT);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_TXFNF);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_TC);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_RXFNE);
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_IDLE);	
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_PE);	
	__HAL_USART_DISABLE_IT(&husart2, USART_IT_ERR);	
	
	//Set the priority of the UART interrupt:
	HAL_NVIC_SetPriority(USART2_IRQn, 3, 0); //(IRQ, priority, subpriority) - lower priority number is higher importance
  HAL_NVIC_EnableIRQ(USART2_IRQn);

However, as soon as I enable the USART2 IRQ, I get USART interrupts triggering (which locks up any other code). The USART interrupts I'm getting are the following:

TXE, TXFNF (TX FIFO not full), TC (transmission complete), and IDLE.

I know this because of my interrupt debug code (shown in this screenshot):

0693W000006HdOPQA0.pngWhy am I getting USART interrupts that I have not enabled?

1 REPLY 1

>>Why am I getting USART interrupts that I have not enabled?

Probably because the register you are reading is flagging internal states, which is then masked by the enable register as it gates those into the interrupt request (singular) which feeds into the NVIC.

Things like TXE will keep asserting if you don't feed in data, if that interrupt is enabled the handler will continuously tail-chain.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..