cancel
Showing results for 
Search instead for 
Did you mean: 

UART Communication

Deepu joy
Associate II

Hi , 

I am using STM32L031x4 MCU for my project. 

In the document it shows 2 UART ports, can I use these 2 UARTS simultaneously ?

I need 2 different UARTS for sensors. 

1 ACCEPTED SOLUTION

Accepted Solutions
Issamos
Lead II

The best way, for me personally, is to use an interrupt function for UART and LPUART that wait for reception and receive data whenever exist .

Best regards.

II

View solution in original post

4 REPLIES 4
Issamos
Lead II

Hello @Deepu joy 

Yes, you can use both uarts for your application.

Hope this is helpful for you.

If your question is answered please check this answer as best answer to be diffused.

Best regards.

II

Foued_KH
ST Employee

Hello @Deepu joy , 

For the STM32L031, you can use I2C / LPUART (Low-power universal asynchronous receiver transmitter) / USART(Universal synchronous/asynchronous receiver transmitter)  for the connectivity .

For the first sensor you can use LPUART1 and for the second USART2.

Foued_KH_0-1693843390483.png
Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

As @Issamos and @Foued_KH say, both Uarts may be used simultaneously.

But there is a caveat. Some of the HAL routines are “blocking” in that when you call them to receive characters on one port, the processor will wait until those characters have arrived. And be unable to receive anything on the other port.

The exception - the routines you could use to enable simultaneous reception - are ones that explicitly mention “DMA” or “interrupt”. Or you could code your own (not easy for a beginner, but you get much better control)

Issamos
Lead II

The best way, for me personally, is to use an interrupt function for UART and LPUART that wait for reception and receive data whenever exist .

Best regards.

II