cancel
Showing results for 
Search instead for 
Did you mean: 

SMT32G030 UART interrupt is triggered as soon as I enable the UART interrupt

DDeba.1
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

>The RX line is currently not connected to anything. Its basically floating 

Switch on pullup in GPIO on that pin, before enabling UART.

JW

View solution in original post

6 REPLIES 6
Nikita91
Lead II

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...

 

Ozone
Lead II

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.

DDeba.1
Associate III

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. 

>The RX line is currently not connected to anything. Its basically floating 

Switch on pullup in GPIO on that pin, before enabling UART.

JW

Nikita91
Lead II

Is also good to reset the UART before configuring it.

DDeba.1
Associate III

Thank you all for your replies. The solution proposed by @waclawek.jan worked perfectly. 

Thanks