Skip to main content
DJ1
Associate III
July 5, 2023
Question

Two STM32 communicating over UART

I have written code for both the transmitter as well as receiver board. The issue is when i see the communication over logic analyzer or even while using TTL to RS232 converter, i can see that the port is continuously occupied and master is transmitting data continuously over Tx and for the same Tx of slave is sending acknowledgement continuously.

In case of ideal situation, the communication should only happen after 1 second not until that. Even if the data is getting transferred continuously, though at every 1 second i can see correct data being transmitted and received by both the boards in their respective debuggers (STM32CubeIDE).

If i remove the connection between both the boards then the master is transmitting only at an interval of 1 second. The issue lies only when both the boards are communicating. Also when both the boards are communicating, i can see OVERRUN, IDLE and RXNE Flag SET in my Status Register. If i remove connection then non of these flags are SET.

Connection: Master          Slave

                     Tx   -----------   Rx

                     Rx  ------------  Tx

Please do share some insights on this!!

This topic has been closed for replies.

7 replies

waclawek.jan
Super User
July 5, 2023

We can't really comment about a program we don't see. But the amount of error may also indicate something unexpected is going on. Check power and reset (e.g. blink a LED upon reset). Are the two boards powered from the same power source? How is ground arranged?

JW

DJ1
DJ1Author
Associate III
July 5, 2023

Receive.c is the master sending the Frame of 50 bytes and Receive_test.c is the slave controller board Code.

Karl Yamashita
Principal
July 6, 2023

It kind of irks me when I see 70-80% of source code inside of an interrupt and you're also transmitting inside of an interrupt. That's all bad practice. Because you're in an interrupt parsing and transmitting, you're going to miss receiving bytes.

Instead save the data, set a flag and exit the interrupt. Then you can poll the flag, then do your parsing and transmitting.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
waclawek.jan
Super User
July 5, 2023

I know I wrote that can't comment code I don't see, but did not expect a whole application, which I'm not going to review.

Try to isolate the problem. As I've said above, check, if hw is OK, first. Then observe in code how acknowledgements are processed - do they cause the repeated transmissions? What happens if in code you disable processing of received bytes (i.e. acknowledgements)?

JW

KDJEM.1
ST Technical Moderator
July 5, 2023

Hello @DJ1 ,

I advise you to take a look at this wiki: Getting started with UART

This article explains what is UART and how to use it through examples using two NUCLEO-L476RG boards

  • Simple UART communication in polling mode
  • UART with Interrupt
  • UART with DMA

I hope this help you!

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
Ozone
Principal
July 5, 2023

> I know I wrote that can't comment code I don't see, but did not expect a whole application, which I'm not going to review.

I would second that.
I just had a look, and didn't really like what I saw.
Waiting for flags (supposedly transmission finished) inside interrupt handlers is IMHO not a good idea.
The OVL flag is a sign you are spending too long in other code, presumably the same interrupt handler.