XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Effective way to communicate Raspberry Pi with STM32

Fri May 11, 2018 1:51 pm

Hello,

I want to communicate a Pi with STM32 within a distance between 7 and 10 feet. Is it suggested to connect directly pins RX and TX without problems and use UART communication? Or should I use line drivers like SP232e (if I use RS232)? Can I use USB ports of the raspberry to communicate with the STM32? I would appreciate any guidance regarding the best way to interface both microcontrollers taking into account possible external noises which could affect communication.

MarkTF
Posts: 270
Joined: Tue Mar 03, 2015 4:59 pm

Re: Effective way to communicate Raspberry Pi with STM32

Fri May 11, 2018 4:43 pm

XaviPacheco wrote:
Fri May 11, 2018 1:51 pm
Hello,

I want to communicate a Pi with STM32 within a distance between 7 and 10 feet. Is it suggested to connect directly pins RX and TX without problems and use UART communication?
Unless you are in a particularly electrically noisy environment, this should work fine over these distances.
Or should I use line drivers like SP232e (if I use RS232)?
This would be more robust than just using the TTL signals, but probably isn't necessary over short distance for a non-critical "hobby project".
Can I use USB ports of the raspberry to communicate with the STM32?
Yes, if your STM32 has USB support hardware and software then you can go USB to USB. This would normally be my preference over using the serial ports as it supports differential signaling and very high data rates.
I would appreciate any guidance regarding the best way to interface both microcontrollers taking into account possible external noises which could affect communication.
What STM32 product and development environment are you using?

XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Re: Effective way to communicate Raspberry Pi with STM32

Fri May 11, 2018 5:19 pm

I plan to use an STM32F446 nucleo board for the first prototype. Globally talking, it's not merely a hobby project (could be considered). The project consist on a treadmill system (that's why I referred to noises, because of the motor). The reason why I want to use a Raspberry is because I want to build a GUI to send commands to the STM32 to operate the treadmill, also through a small monitor I plan to display time, distance, velocity, heart rate, etc. But the Raspberry isn't going to control all that, it's just going to send or receive data and display information. The power and peripheral management in general will be handled by the STM32, like sensors, PWM of the motor, etc. Also, I chose Raspberry because I'm not expert programming GUIs, and I found much information on the web about it. So I think it's easier for me if I use it.

Most treadmills use a upper board and lower board. I just thought I could get the raspberry and STM32 together in a lower board, and I just have the monitor as the "upper board". In that case, the raspberry and stm32 would be really close physically. But if I choose to put the raspberry in the upper side and STM32 in the lower side, the wire distance between them would be like 7 or 9 feet.

The project is in its early phase, so I accept any suggestion or change.

User avatar
mark3112
Posts: 35
Joined: Mon Apr 09, 2018 10:39 am

Re: Effective way to communicate Raspberry Pi with STM32

Fri May 11, 2018 8:23 pm

CAN could be an option or RS-485.
The STMF4xx range normally have two CAN Controllers built in, so would only need an Interface Chip (see MCP2551 as an example) and the pi end could use the MCP2515 on an SPI port (and another Interface Chip).

https://en.wikipedia.org/wiki/CAN_bus
You can make a real CPU in a FPGA, but you can’t make a real FPGA in a CPU.

XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Re: Effective way to communicate Raspberry Pi with STM32

Fri May 11, 2018 8:32 pm

Okay, but just in case I choose to place both the Pi and STM32 really close each other, would those drivers be essential? If I choose to place the Pi in the upper board and the STM32 in the lower board, I would consider the drivers as distance increases.

User avatar
mark3112
Posts: 35
Joined: Mon Apr 09, 2018 10:39 am

Re: Effective way to communicate Raspberry Pi with STM32

Sat May 12, 2018 8:42 pm

If they are close together, just use I2C, SPI or RS-232.
You can make a real CPU in a FPGA, but you can’t make a real FPGA in a CPU.

XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Re: Effective way to communicate Raspberry Pi with STM32

Wed May 16, 2018 5:58 pm

I've decided to use RS232. So what chips/drivers should I use between the STM32 and the Pi? Like the SP232een, for example?

drgeoff
Posts: 8746
Joined: Wed Jan 25, 2012 6:39 pm

Re: Effective way to communicate Raspberry Pi with STM32

Wed May 16, 2018 6:34 pm

XaviPacheco wrote:
Wed May 16, 2018 5:58 pm
I've decided to use RS232. So what chips/drivers should I use between the STM32 and the Pi? Like the SP232een, for example?
MAX3232. Will operate from 3.3 volts and includes the charge pumps to generate the voltages required for true RS232.

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Effective way to communicate Raspberry Pi with STM32

Wed May 16, 2018 9:07 pm

If you're going to use serial, I suggest you at least consider RS-422. Using differential signalling, it has much better noise immunity than RS-232, and can operate over much longer distances, although that's unlikely to be an issue for you here.
A device from the MAX3483-MAX3491 group would do the job - probably MAX33488 or MAX3490.
And if you used the MAX3491, you'd have the possibility of moving to a multi-drop system later; maybe multiple slave processors might be useful on an advanced machine, or would simplify wiring.

XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Re: Effective way to communicate Raspberry Pi with STM32

Wed May 16, 2018 9:28 pm

Thanks for your suggestions. I will finally consider RS232 for my application. I know that other protocols offer better characteristics, but RS232 would work here.

Another question, as I will use MAX3232, should I supply it with 3.3V right? As STM32 and Pi works with 3.3V, I need the charge pump for 3.3V to RS232 levels. If I supply the MAX with 5V then the RX/TX signal will be at 5V also, right?

User avatar
mark3112
Posts: 35
Joined: Mon Apr 09, 2018 10:39 am

Re: Effective way to communicate Raspberry Pi with STM32

Thu May 17, 2018 8:56 am

As you are connecting directly you don’t need RS-232 line drivers.
If the devices are very close just connect them TX-RX and RX-TX.
If they are not close you could use differential line drivers i.e. see SN65LVDS180
Attachments
Line Driver.png
Line Driver.png (16.42 KiB) Viewed 1391 times
You can make a real CPU in a FPGA, but you can’t make a real FPGA in a CPU.

User avatar
davidcoton
Posts: 3252
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Effective way to communicate Raspberry Pi with STM32

Thu May 17, 2018 9:56 am

XaviPacheco wrote:
Wed May 16, 2018 9:28 pm
Thanks for your suggestions. I will finally consider RS232 for my application. I know that other protocols offer better characteristics, but RS232 would work here.

Another question, as I will use MAX3232, should I supply it with 3.3V right? As STM32 and Pi works with 3.3V, I need the charge pump for 3.3V to RS232 levels. If I supply the MAX with 5V then the RX/TX signal will be at 5V also, right?
The voltage on RS232 can be anywhere from +/- 3V to +/-24V (IIRC). The driver chip incorporates the charge pumps. The chip voltage, its supply, and the GPIO voltage MUST match (3V3 for the Pi, the other end could be different).
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

XaviPacheco
Posts: 28
Joined: Fri May 11, 2018 1:41 pm

Re: Effective way to communicate Raspberry Pi with STM32

Thu May 17, 2018 1:11 pm

I have one last question, is optoisolation needed? I have seen circuits where they place an optocoupler after TX and RX pins of the microprocessor.

Heater
Posts: 10234
Joined: Tue Jul 17, 2012 3:02 pm

Re: Effective way to communicate Raspberry Pi with STM32

Thu May 17, 2018 2:14 pm

Use of opto-isolation depends on the nature of the link, how long, how fast, what devices on each end, how are the powered.

Basically opto-isolation is all about protecting devices from any dangerous voltages that may be incoming. For short links in clean environments using clean power supplies it rarely necessary.

Sometimes you cannot be sure that the ground (0V) on both end of the links is always the same. Opto-isolation protects devices from being destroyed by such offsets.

Return to “General discussion”