Issues using UART between 2 Raspberry Pi boards

4 views (last 30 days)
Hi everyone,
For a project, I need to do a communication between 2 Raspberry Pi 4B boards using Simulink in MATLAB R2020b (this version is mandatory). This communication needs to be fast to be able to do Hardware-In-the-Loop simulations (approximately 500-1000Hz). I saw that using UART seemed to be a good solution to do this as theoretically it can communicate fast enough.
First thing, I wanted to just test this UART communication with a simple code. This code does a blinking sequence of the ACT LED of one board (RPi 1) and then this sequence is sent from the RPi 1 board to the other one (RPi 2). The problem is that when I am sending this sequence as a vector of size [6x1] for example from the RPi 1 at a sample rate of 0.001s, the RPi 2 doesn't get the expected vector in return. Instead, it returns inconsistent values that clearly doesn't correspond to what I sent in the first place. But when I decreased the sample rate to about 0.1s, the communication is done without any errors.
I tried to change the baudrate to its maximum, increase the sample rate of the "Serial Read" block of the RPi 2 side (until 0.5s), change the wires in my configuration, and also change the type of data I am sending ("single" values) but this didn't seem to change anything. I really need the sample rate to be about 0.001s which is why I am requesting your help. What did I do wrong here ? Is there a better way to transfer data for what I want to do ? Could that be a software issue ?
About my configuration, it is just a simple one where the TX of the RPi 1 is connected to the RX of RPi 2 and vice versa, and both boards on the same GRD.
One piece of information that could be relevant is that both boards are running with the MathWorks OS (MathWorks Raspbian Image v20.1.0). This one wasn't adapted to the Raspberry Pi 4B boards so I had to change some files in the microSD card (.elf and .dat ones) so that the boards could boot. Instead of this trick, the boards work fine with MATLAB/Simulink. I also wish to not change this OS if it's possible.
Thank you for your reading and your help !
  2 Comments
Prasanth Sunkara
Prasanth Sunkara on 15 May 2024
Hi Romain,
How did you configure the "Serial Read" block? Was it set to read only one byte every sample time or 6 values per sample time? It would be great if you can attach your Simulink models to this question.
-Prasanth
Romain Miaux
Romain Miaux on 15 May 2024
Edited: Romain Miaux on 15 May 2024
Hi Prasanth,
Thank you for your fast response !
I attach to this answer my models so that it would be easier for everyone. Also, my "Serial Read" block is configured as follows:
In my case, I am using a 12-element vector for the sequence.
- Romain

Sign in to comment.

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!