SoftwareSerial doesn't work on Nucleo-32L031K6

I use Arduino IDE and "STM32 MCU based boards" to program Nucleo32. Here are the settings:
image

I connect it directly to computer using USB.

Here is my code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(PB6, PB1);  // RX, TX

void setup() {
    Serial.begin(115200);
    Serial.println("Hi");

    mySerial.begin(115200); // When I add this line, nothing works anymore
}
void loop() {
    if (Serial.available()) {
        String command = Serial.readStringUntil('\n');
        Serial.print("Just received a Serial from PC: ");
        Serial.println(command);
    }
}

I reset it and it writes "Hi" in the Serial monitor, but when I begin() the software serial (line 8), nothing works anymore. Unable to toggle pins, no output appears in the Serial monitor and everything gets stuck.

When I remove line 8, it works without any problems.

Try SoftwareSerial with a much lower baud rate and see what happens. Try 9600 to start.

1 Like

With all the information provided I will take a SWAG and say It’s generally recommended to use hardware serial ports instead, as STM32 boards typically have multiple hardware serial ports available. Hardware serial offers better performance and reliability compared to software serial.

1 Like

9600 the same. I'm trying with HardwareSerial to see if it works or not.

Even a negative result can be useful. It rules out trying to run SoftwareSerial at an unusually high baud rate as the problem.

1 Like

millis() function doesn't work too! I don't like it at all. Weird problems without errors. Switching to Atmega328. Thanks all

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.