2020-08-05 01:44 AM
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);
2020-08-05 02:19 AM
Well, it does signal that the line has entered the IDLE condition. What is the problem here?
2020-08-05 05:14 PM
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.
2020-08-05 08:48 PM
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.
2020-08-05 09:39 PM
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.
2020-08-06 06:08 PM
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.
2020-08-06 06:10 PM
Thanks for reply.
The problem is that it trigger an idle condition without a communication.
2024-07-03 04:53 AM
Hey!
Sorry for reviving an old topic, I found the same behaviour. Chip is STM32G4. Here is my receive code:
void usart_start_reception(void)
{
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1); // Do not Clear Channel global interrupt flag when the channel in ON. bug id 2.3.1 in Product Errata Sheet.
LL_DMA_ClearFlag_GI1(DMA1);
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, sizeof(usart_rx_dma_buffer));
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
LL_USART_EnableIT_PE(USART1);
LL_USART_EnableIT_ERROR(USART1);
LL_USART_EnableDMAReq_RX(USART1);
LL_USART_ClearFlag_IDLE(USART1);
LL_USART_EnableIT_IDLE(USART1);
}
And here's Cube generated USART initialisation:
void MX_USART1_UART_Init(void)
{
//...
LL_USART_Enable(USART1);
/* Polling USART1 initialisation */
while((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1))))
{
}
/* USER CODE BEGIN USART3_Init 2 */
LL_mDelay(1);
usart_start_reception();
/* USER CODE END USART3_Init 2 */
}
I noticed that without an artificial 1ms delay, the USART IDLE interrupt will fire the first time even without any data on the rx line.