2023-07-06 12:45 AM
Hi,
I developed an application using the STM32G030 having UART working with interrupts. The UART initialization is done by the STM32CubeMX (attached). In addition, I have added code to enable the RXNE and Error interrupts using the LL functions "LL_USART_EnableIT_RXNE_RXFNE(USART1)" and "LL_USART_EnableIT_ERROR(USART1)". Everything works fine except that as soon as the UART is enabled, the CMF, RXNE and FE flags are set and an interrupt is generated (since I have previously enabled the RXNE and Error interrupts).
Is there any reason why the CMF, RXNE and FE flags are set as soon as the UART peripheral is enabled?
Thanks
Solved! Go to Solution.
2023-07-06 10:50 AM
>The RX line is currently not connected to anything. Its basically floating
Switch on pullup in GPIO on that pin, before enabling UART.
JW
2023-07-06 02:54 AM
Set a break point in the interrupt handler then check which interrupt is enabled in CR1, which interrupt flag is present in ISR. If you see CMF check the "Character Match" configuration.
Does the RX line is active : another device is sending data on RX at the time you enable the interrupts?
It looks like your RX line is noisy...
2023-07-06 05:00 AM
In my experience, this is a common experience. I came across such an issue with several MCUs, not only Cortex M.
Either signals during startup create events the peripheral unit interprets as Rx or error events, or the spurious flags are produced internally. More often than not, MCU manuals do not cover it. An, peripheral IP is often relative opaque anyway (i.e. the vendor does not disclose many details).
The best solution is IMHO to cover such cases appropriately in the interrupt handler.
If necessary, even clearing all flags at the first invocation.
2023-07-06 07:50 AM
Hi,
Thanks for the replies.
@Nikita91 The RX line is currently not connected to anything. Its basically floating (with a 1nF cap connected to GND for filtering). The only interrupts I have enabled are the ones I mentioned. From what I can tell, I'm assuming that the framing error is the one triggering the interrupt.
@Ozone I also came across devices which had this issue and usually thier errata sheet gives a work around or the data sheet specifies a sequence in which the interrupts needs to be enabled for this not to happen. In this case, I didn't find anything on iether the errata sheet or the datasheet. I guess the best solution would be to enable the USART before enabling the interrupts, clear the flags and than enable the interrupts.
2023-07-06 10:50 AM
>The RX line is currently not connected to anything. Its basically floating
Switch on pullup in GPIO on that pin, before enabling UART.
JW
2023-07-06 11:59 AM
Is also good to reset the UART before configuring it.
2023-07-07 01:04 AM
Thank you all for your replies. The solution proposed by @waclawek.jan worked perfectly.
Thanks