2019-11-12 11:16 PM
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.
Solved! Go to Solution.
2019-11-13 06:00 AM
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.
2019-11-12 11:32 PM
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
2019-11-12 11:37 PM
One can handle with a single interrupt, keep it simple, and only input / output to a ring buffer based on the flagging interrupt sources.
2019-11-13 03:50 AM
Hi @Community member
Can you please elaborate that in detail.
2019-11-13 06:00 AM
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.
2024-12-04 04:43 AM
How do you access bits in registers with the HAL? There's a lot of detail that's masked & not available by using the HAL functions. Also, how do you generate timeouts? In a simple polled UART application, I just call HAL_UART_Receive_IT with a 10 second timeout to give me time to type a string into my terminal emulator. The interrupt version doesn't wait, so how do I gather characters into a buffer?
2024-12-04 02:00 PM - edited 2024-12-04 02:01 PM
@Ken Macfarlane wrote:How do you access bits in registers with the HAL? There's a lot of detail that's masked & not available by using the HAL functions. Also, how do you generate timeouts? In a simple polled UART application, I just call HAL_UART_Receive_IT with a 10 second timeout to give me time to type a string into my terminal emulator. The interrupt version doesn't wait, so how do I gather characters into a buffer?
Use HAL_UART_Receive_IT to receive 1 byte at a time and you don't need a timeout. Set the terminal to send a LF when you press Return. As you type characters, you'll get an interrupt. Save each character received to a buffer and when you get a LF, you can set a flag to indicate you have a complete message..