after looking up this problem quite a bit I'm unable to find a solution on my own. I have to set up a serial communication between 3 devices.
Device #1 is made by my company. I cannot tell what it is, but it uses an STM32 MCU.
Device #2 is a Nucleo 144 board, of which the software is written using Arduino IDE
Device #3 is a regular PC, running a terminal allowing me to read/write from/to a serial port
I wish to have Device #1 write on its TX pin, connected to my Device #2 (nucleo)'s hardwareSerial RX (D52), and have Device 2 output that same thing over USB to my Device 3 (PC). I have done this with various devices in the past and I can't comprehend why it does not work in this instance.
When I connect device #1 directly to the PC (#3) via an USB serial it works fine. I read everything without any issues. There is no garbage, etc.
when I connect device #2 directly to the PC (#3) it works as well. Simply writting to serial.
When I connect #1 to #2 (hardwareSerial OR softwareSerial) and #2 to #3 (USB) it fails: first Device #2 outputs a normal message (UART TEST) on the USB serial which shows that the USB connection works.
Then, as I redirect the output of Device #2 RX to the USB Serial, everything turns into garbage (seemingly random characters) although you can make out the same formatting as expected (messages that look like the real ones, in size and frequency)
I have tried various combinations of baudrates but device #1 is forced to output at 115200. Electronically, there is a direct connexion between D52 and PA9, D53 and PA10.
Here is the code on device #2 (Nucleo 144)
#include <HardwareSerial.h>
#define BAUDRATE_USB 9600
#define BAUDRATE_BOARD 115200
#define RX_PIN D52
#define TX_PIN D53
HardwareSerial boardSerial = HardwareSerial(RX_PIN, TX_PIN);
void setup()
{
pinMode(RX_PIN, INPUT);
pinMode(TX_PIN, OUTPUT);
Serial.begin(BAUDRATE_USB);
boardSerial.begin(BAUDRATE_BOARD);
delay(10000);
char str[] = "Test UART";
Serial.write(str, sizeof(str));
}
void loop()
{
delay(100);
while (boardSerial.available() > 0)
{
byte b = boardSerial.read();
Serial.write(b);
}
}
As mentionned I have tried various baudrates including matching ones for every serial, to no success. The payloads come in as gibberish (bunch of random characters, letters with accents etc) It's worth noting that it's the same gibberish every time however.
I probably cannot show the code used on the board that has a STM32 controller on it. I use the pins PA9 and PA10 (tx and rx respectively), let the IDE configure them for me and write/read on the usart when needed. This works, as demonstrated by the fact that the information that we expect it to send is well received when connected to a computer over USB serial.
I'm lost at this point. Everything I do (Using Serial1, using softwareserial, using hardware serial, and some more ways I've forgotten) all yield the exact same result.
I am assuming my problem is either on the arduino/nucleo side of things.
thanks in advance, I will keep looking into the problem on my side and will check this thread periodically.