cancel
Showing results for 
Search instead for 
Did you mean: 

Usart idle interrupt question

PZhou.1
Associate II

Hello,

When I enable usart idle interrupt function on stm32g071rb, it fires the interrupt immediately even there is no communication on the bus.

I debug use cubeide and IAR. The results are the same.

When UE bit in USART_CR1set to 1, the IDLE bit in USART_ISR will change to 1 right now.

So after IDLE interrupt enabled, it will cause a interrupt.

I don't know why the IDLE bit in USART_ISR change to 1.

And I try to clear the IDLE bit in USART_ISR, by set IDLECF bit in USART_ICR before enable the interrupt. It no works.

But I add a delay_1_ms between uart_init and clear Idle interrupt flag, it works.

The code is below:

 MX_USART1_UART_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 HAL_Delay(1); // work with this

 __HAL_UART_CLEAR_IDLEFLAG(&huart1);

 __HAL_UART_CLEAR_IDLEFLAG(&huart2);

 __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);

 __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);

6 REPLIES 6
Piranha
Chief II

Well, it does signal that the line has entered the IDLE condition. What is the problem here?

The problem is that there is no communication on the uart receive line. So it doesn't need the condition for idle interrupt.

Even I clear the interrupt flag before enable this interrupt, it seems the flag can't be cleared.

I must add a delay, later the problem disappear.

TDK
Guru

Possibly it doesn't trigger an idle condition until the first definitive stop bit is received, which would occur around 10 or so bits after initialization.

If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

Check the sequence between gpio and usart init. if gpio is done later, for a short while the usart is exposed to the unknown floating node.... strike throught this concern by checking it.

Thanks for reply.

My doubt is same as you.

The init of usart is create by cubeIDE use HAL lib. I think the procedure are same between F103 and G071. Same code in F103 and G071, the phenomenon

are different. F103 is OK, but G071 is not. It confused me.

Thanks for reply.

The problem is that it trigger an idle condition without a communication.