-3

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.

Tohkai
  • 93
  • 1
  • 9
  • 2
    is Serial Monitor set to 9600 baud? is ground connected between the MCUs? – Juraj Jun 23 '23 at 14:15
  • @Juraj yes, the monitor is set to 9600 I am unable to tell about the ground question since the person who makes the hardware isn't here with me (the nucleo is plugged on a PCB which redirects outputs to various places - in the case of the RX and TX pins, it's just a direct line) – Tohkai Jun 23 '23 at 14:28
  • 1
    I assume you're doing something like: `D1/TX --> D2/RX`, `D2/TX --> D3/RX`, `D3/TX --> D1/RX` What about the ground wires? `D1/GND`, `D2/GND`, and `D3/GND` must all be connected. What is the length of the cables? Are the devices connected to the same power strip? If the data GND are _not_ connected, the AC power GND can function as a poor data GND. Are any of the units using _differential_ line drivers? What about the RTS and CTS wires? How are they connected? Are they disabled in S/W on all devices? – Craig Estey Jun 23 '23 at 15:04
  • @CraigEstey thank you for the feedback, I will return to you with an answer probably on monday as apparently I can't have access to this information right now, however I will look into it. – Tohkai Jun 23 '23 at 15:07
  • As soon as I saw your company will not let you tell what it is I stopped. You should have someone at your company pay to have someone help you. This is volunteer support for hobbyists. Not free labor for your company. – Delta_G Jun 24 '23 at 16:38
  • fair enough, I'll see this with them. – Tohkai Jun 26 '23 at 07:25

1 Answers1

0

Diagrams that I didn't have access to showed that bytes are inverted on the serial. I needed to invert the logic, for instance:

SoftwareSerial boardSerial = SoftwareSerial(RX_PIN, TX_PIN, 1);

(third argument being "true" for inverted logic) I had no idea this was a thing that was actually done.

Tohkai
  • 93
  • 1
  • 9