2023-09-04 08:39 AM
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.
Solved! Go to Solution.
2023-09-04 09:41 AM
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
2023-09-04 08:48 AM - edited 2023-09-04 08:49 AM
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
2023-09-04 09:01 AM - edited 2023-09-04 09:03 AM
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
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.
2023-09-04 09:32 AM
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)
2023-09-04 09:41 AM
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