Page 1 of 1

Serial monitor

Posted: Sat Jan 22, 2022 5:02 pm
by mebab
I have developed an stm32L based application using Arduino IDE. I need to debug the code. How to define USART2 (RX, TX) to communicate via a USB-TTL converter?

Thanks for your kind help

Re: Serial monitor

Posted: Sat Jan 22, 2022 6:19 pm
by GonzoG
Just define HardwareSerial object and use it same as "standard" Serial (eg. Serial1.write(), Serial1.print())
https://github.com/stm32duino/wiki/wiki ... wareserial

Re: Serial monitor

Posted: Sat Jan 22, 2022 8:51 pm
by mebab
Thanks a lot, Gozog!

I did as you mentioned in a simple code for STM32L433 as follows:

Code: Select all

//                      RX    TX
HardwareSerial Serial2(PA15, PA2);

void setup() {
  Serial2.begin(115200); 
}

void loop() {
  Serial2.println("Hello World!");
  delay(1000);
}
However, I receive the following error message:

Code: Select all

Error opening serial port 'COM21'. (Port busy)
What is the reason for the port to be busy?

Re: Serial monitor

Posted: Sat Jan 22, 2022 8:57 pm
by GonzoG
It's exactly what it's written there: "Port busy" - something is using it.
And it has nothing to do with MCU. This COM port is your USB-TTL adapter.

Re: Serial monitor

Posted: Sat Jan 22, 2022 9:18 pm
by mebab
I have nothing else than the USB-TTL adapter which is connected to the following pins on my board:

Code: Select all

3.3V
GND
TX-->RX2 or TX2
RX-->TX2 or RX2
When I change the port number via 'Device manager', I still receive a similar error with the new port number!
what might be the solution? changing the port number to any specific one or what?
I even closed Arduino IDE and used putty to see if it helps to bypass the port busy issue. But it didn't help. There is nothing else left to close or disconnect!
As you mentioned, USB-TTL is using the same port number. On the other hand, we use this device to see the same serial port. It is confusing to know what to do.

Re: Serial monitor

Posted: Sat Jan 22, 2022 9:41 pm
by GonzoG
The COM port you see on your computer has nothing to do with your STM board.
It's an USB-TTL adapter and computer connects with this adapter, not MCU.

If you cannot open COM port, then something on your PC is using this port.

Re: Serial monitor

Posted: Sat Jan 22, 2022 10:13 pm
by mebab
Sorry! I changed the port number of the USB-TTL adapter to many others via 'Device manager'. However, it didn't help. Whatever free port number I assign, is represented busy by Arduino IDE or Putty. I don't know what is left to do!

Re: Serial monitor

Posted: Sat Jan 22, 2022 10:27 pm
by GonzoG
1. your USB-TTL adapter might be faulty
2. you have wrong driver for your adapter
3. there is a program on your PC that connects automatically to any available COM port.

Re: Serial monitor

Posted: Sun Jan 23, 2022 2:28 pm
by mebab
Thank you GonzoG!

I updated the firmware of the USB-TTL adapter and the problem is solved now.

Thanks again,
Mehrdad