cancel
Showing results for 
Search instead for 
Did you mean: 

How can work with UART in Interrupt mode transmit and receive some amount of data in byte by byte?

Vel
Associate III

Hi,

I am working on two STM32 microcontrollers communicating over UART with baud rate 9600. The functional requirement states that I need to transmit and receive data at both microcontrollers. Currently this is not happening as the transmit and receive interrupts conflict I suppose. Please guide me for this problem statement.

1 ACCEPTED SOLUTION

Accepted Solutions

You're familiar with the concept of ring/fifo buffers, right?

The USART IRQ Handler should test for the RXNE status and move the data register to a receive buffer, and then check TXE and if a transmit buffer has any data, if there is data that gets sent, if not the TXE is disabled.

When you put data in the transmit buffer you also enable the TXE interrupt again.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

https://community.st.com/s/question/0D50X0000BVpldhSQB/how-to-have-continuous-uart-burst-transmit-while-ensuring-receive-works-

JW

@Vincent Onde​ 

So this might be the basic "how to bring up UART" AN. Starting with the "test pins by wiggling them as Out/In", moving on to trivial polled implementation perhaps first using a loopback, then connecting to real counterpart and doing a software echo (perhaps with slight modifications); then moving on to the simplest interrupt based one, outlined above, with highlighting the overrun gotcha. Discuss RS232/level conversion issues. Discuss baudrates, primary clock precision impact - mutual mismatch of both parties, impact of fractional baudrate, impact of oversampling (maybe this all ought to be another appnote); hint about autobaud (which ought to be a separate AN in the UART dozen), point to the bintbanged USART appnote.

JW

One can handle with a single interrupt, keep it simple, and only input / output to a ring buffer based on the flagging interrupt sources.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi @Community member​ 

Can you please elaborate that in detail.

You're familiar with the concept of ring/fifo buffers, right?

The USART IRQ Handler should test for the RXNE status and move the data register to a receive buffer, and then check TXE and if a transmit buffer has any data, if there is data that gets sent, if not the TXE is disabled.

When you put data in the transmit buffer you also enable the TXE interrupt again.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..