cancel
Showing results for 
Search instead for 
Did you mean: 

Communicating 10 STM32F429x parallelly with PC program.

FLast.5
Associate II

I have to connect 10 devices based on STM32F429x MCU to PC and run them in parallel and send log data from all those STM32F429x devices to PC.

Previously when using 1-2 ARM devices with PC I had been using serial port with RS3232 and USB-serial converter to transfer data from my device to PC. My PC program is written in C# using its serial port interface.

The data size transferred from device to PC is 1~2 Kb per device and control signals to individual devices (few bytes). All of them need to run parallelly and will probably send data at almost same time. Timing for log data transmission depends on completion of tasks in each ARM devices but there is no big difference on completion of tasks (probably ~300 ms difference maximum). And the result is to be displayed in PC in real time.

For 10 devices, I don't know if RS3232 would be problem. I do not want to go with USB expansion hub because the ports keep changing whenever PC reboots. Can I use RS-3232 and USB-serial converter with Serial expansion card or Ethernet-Serial converter connected to router to PC ? (Ethernet-Serial converter to avoid IP related complexities.)

If I go with Ethernet method what should be the communication mechanism in c# ?

I want to know which one would be better solution.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
10 REPLIES 10
berendi
Principal

What best suits your situation is depending on your requirements. How much data, what latency?

Ozone
Lead II

You can tinker with the packet size and latency (poll rate) of the USB driver on PC side, to avoid data loss.

If you do not run each of the nodes at full bandwidth capacity, a decent PC should be capable of handling it - most of the time.

But Windows (and Linux or MacOS) is no real-time OS, it will faint in high-load situations.

If can't have data loss/overrun, use handshake and a safe protocol.

Data is 1-2 Kb. Time delay among each transmitting devices 300 ms at maximum.

That should be manageable.

Assuming Windows as host OS, I still suggest do some proper planning beforehand.

Most USB-serial adapters state their driver chip, including internal buffer (FIFO) capacity. I would go for one documenting such features.

Considering your baudrate, you can configure your host USB driver (poll rate and buffer size) according to your requirements.

To reduce complexity on both the device and the PC side, I would daisy chain the devices, using two serial ports on each one. So e.g. UART1 on MCU1 is connected to the PC, UART2 of MCU1 goes to UART1 of MCU2 and so on.

Make the data packet size fixed, so that data transfers can be handled automatically by DMA, making the impact on the MCU speed negligible.

Each MCU could buffer the incoming packets from dowstream, and send it upstream when the receive is complete. Make sure that there is enough pause between packets, so the neighbour can empty its buffer before the next one comes (in case there's not enough free RAM to buffer several packets).

Configuration packets from the PC could include a counter, which is decremented by each station before forwarding. When the counter reaches 0, it has reached the destination, and the MCU can interpret is instead of forwarding.

Piranha
Chief II

You can do it using RAW Ethernet without IP stack. Here is what you get "for free" with Ethernet hardware:

  • Collision avoidance.
  • Data messages instead of stream.
  • Scatter/gather DMA.
  • CRC checking.
  • Robust physical connection.
  • Vast scalability with switches, which also do additional frame buffering.
  • No additional hardware needed on PC side.

Also note that on the MCU side sending/receiving RAW Ethernet frames is far more easier than dealing with USB stack. It's even easier than managing USART properly!

On a PC side: https://stackoverflow.com/questions/3964013/how-send-raw-ethernet-packet-with-c

Jack Peacock_2
Senior III

Another alternative is to replace the RS-232 with half-duplex RS-485, assuming your 10 devices are relatively close together (meter or more separation, 1km end to end). On the PC side use a USB to RS-485 adapter, which appears as a COM port on the PC. Use the COM port API in C# to communicate.

With RS-485 all devices share a common bus. The STM32s listen for an address command from the PC, and then the selected device responds with data back to the PC. There is the added complication of half-duplex with line turnaournd but this isn't difficult to implement. If you want to use a standard protocol for this take a look at Modbus.

RS-485 is a very common industrial interface used to replace RS-232 when devices are networked, or if noise immunity is an issue. RS-485 can operate at higher speeds over a longer distance with greater reliability compared to RS-232.

BTW if you see a USB device constantly changing ports when connected to a PC it's because the USB device is not reporting a serial number to uniquely identify itself. The PC has no way of knowing you are using the same adapter more than once. A well made USB device will always report a serial number, allowing the OS to assign a fixed COM port for serial.

Jack Peacock

Pavel A.
Evangelist III

This is working great for me. Thanks.