UART Communication between STM32 and Raspberry Pi.

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
Hello,

I want to communicate an STM32 with a Raspberry Pi using UART. But I wonder if I need Line Drivers/Receivers like SP232E between microcontrollers. I mean, If I use RS232, would it make communication more reliable? Or does it depend on the distance between MCUs? What exactly can define if I should use drivers or simply connect directly RX and TX pins?
 

dendad

Joined Feb 20, 2016
4,451
If they both run on the same volts, like 3.3V, connecting them directly should not be a problem. But it will only work reliably over a relatively short distance. An RS232 driver at each end will increase the distance but if you want longer, use RS485 drivers. They will work ok for a km if needed.
 

be80be

Joined Jul 5, 2008
2,072
You most times don't need line drivers if they are close.

You sure don't if there in the same room LOL.
Like a 10 x 10 room LOL
100 feet away you'll need them.
 

dendad

Joined Feb 20, 2016
4,451
I just had a look at the SP232E, and what you will need to take note of is the power supply voltage of your drivers. Check to see if the driver in question will send 5V signals to the 3.3V processors. If the processor inputs are not 5V tolerant, you could damage them. There are 3.3V versions of line drivers available, or you may need level shifters of some sort between the processors and the drivers.
 

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
Both Raspberry Pi and STM32 I think work with 3.3V, so as you say, connecting them directly shouldn't be a problem. They are relatively close, like 7 or 8 feet.
 

dendad

Joined Feb 20, 2016
4,451
Give it a try and see how it works. A long as there is not electrical noise nearby you should get away with it. If there is trouble, try lowering the baud rate.
 

dendad

Joined Feb 20, 2016
4,451
Close to the boards will be a power DC motor running, would it affect communication?
DC motors are pretty bad for noise generation. Make sure you don't run the comms wires near the motor wires. We had a lot of trouble in an installation as the electricians ran the comms cable in a tray with the cables between a fairly high power motor and the Variable Speed Drive.

Line drivers like the RS485 and 232 can usually run into lower impedance loads than just using the port pins.
Also it may be worth shielded comms wires although that could limit the speed on plain "TTL" levels.
For best results, use the correct impedance shielded cable for your communications. And the termination resistors may be needed. Getting comms working correctly sometimes is tricky, even though it should be straight forward. One of the problems is often the wiring is done by others and them we would come in and have to make it work.
On all our systems we use RS485 half duplex comms but you could have 2 x driver chips at each end and run full duplex. The RS485 chips run differential lines so have a built in noise tolerance.
https://www.exar.com/ds/sp3485_100_061912.pdf
In a lot of applications, the RE/DE pins are hooked together and a port pin drives them to control the direction.

These chips only need on at each end as they are full duplex...
http://www.ti.com/product/SN65HVD37

There are lots from various companies to choose from. Here are a couple of links to help explain.

https://www.intersil.com/content/dam/Intersil/whitepapers/interface/rs-485-transceiver-tutorial.pdf
http://www.windmill.co.uk/rs485.html
 

Sensacell

Joined Jun 19, 2012
3,432
For short distance TTL to TTL serial interfaces:
The physical "distance" between the transmitter and receiver is not as important as is the integrity of the ground reference between circuits.

You can have two boards inches apart - high current pulses from a motor can wreak havoc.
Careful consideration of where currents flow in ground conductors can save you from much pain.
Avoid using wires that carry high currents as ground references for signals, consider a "star" ground configuration.
 
Top