cancel
Showing results for 
Search instead for 
Did you mean: 

Connection between 2 stm32 mcu boards using uart with only one USB cable

Desireee
Associate

How do I connect 2 mcu stm32 nucleo l053r8  boards using uart with only one  USB cable and how do I check if connection is established using led

6 REPLIES 6

How exactly would this work?

The ST-LINK is not implementing a USB Host.

Why wouldn't you just connect up a UART more directly?

On the PC side you could write an app to move data between COM ports at the ST-LINK level.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FBL
ST Employee

Hi @Desireee 

I may suggest using USB UART bridges to send and receive data. Here is an example 

Configure the USB OTG peripheral on the Host board to operate in Host mode.
Configure the USB OTG peripheral on the Device board to operate in Device mode.
Implement data or file transmission (Host to Device) and data reception (Device to Host) through CDC class.

Ensure the USB device is configured correctly in the usbd_cdc_if.c file then use CDC_Receive_FS function to handle received data through the Hyperterminal.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Andrew Neil
Evangelist III

@Desireee wrote:

connect 2 mcu stm32 nucleo l053r8  boards using uart with only one  USB 


What do you mean by that?

The only USB connection on the Nucleo-L053R8 is the ST-Link - you cannot connect those directly together!

As @Tesla DeLorean said, if you want a UART connection, just wire between the UART pins on the Arduino and/or Morpho connectors:

AndrewNeil_0-1726221127686.png

Check the Datasheet for UART pin assignments:

https://www.st.com/en/microcontrollers-microprocessors/stm32l053r8.html#documentation

 

Note that the ST-Link's VCP connects to PA2 and PA3 - so you'll have to disconnect that to use those pins.

 


@Desireee wrote:

how do I check if connection is established using led


  1. Send a message from one board to the other
  2. On the receiving board, verify that the correct message is received
  3. Light the LED if it's OK.

But don't start by trying to do this all at once - a common beginner's mistake.

Instead, take it one simple step at a time:

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719485/highlight/true#M260696

In this case, start by testing your serial comms against a terminal on a PC.

Only connect the two boards together once you know that both your receiving and transmitting code is fully working and debugged.

Don't try to do both ends at once:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/i2c/m-p/668411/highlight/true#M18743


@FBL wrote:

Configure the USB OTG peripheral on the Host board to operate in Host mode.
Configure the USB OTG peripheral on the Device board to operate in Device mode.


But the STM32L053R8 (the device on the Nucleo-L053R8) doesn't have OTG - it's Device only:

AndrewNeil_1-1726222692585.png

 

 

How many USB Cable do I need to upload the code? As I'm a beginner I do not know how to establish connection between 2 mcu boards. What I did for now is only connecting Tx-->Rx , Rx-->Tx and random 2 ground from each board connect together using manual connection


@Desireee wrote:

How many USB Cable do I need to upload the code?


One per board.

If you do one board at a time, then just one cable.

 


@Desireee wrote:

What I did for now is only connecting Tx-->Rx , Rx-->Tx and random 2 ground from each board connect together using manual connection


That's correct - and not specific to STM32:

 

AndrewNeil_1-1726231091365.png

https://learn.sparkfun.com/tutorials/serial-communication/all 

 

Again, as a beginner, don't jump straight into trying to do this all at once - take just one small, simple step at a time.

As per the previous link:

  1. Write some code to blink the LED on one of your Nucleo boards, using a simple software loop.
  2. Learn how to use the debugger to step through your simple LED code, look at your variables, set breakpoints, etc 
  3. Write code to use the UART on one of your Nucleo boards to transmit a fixed "Hello, World " string over the ST-Link VCP to a terminal on your computer.
    Again, 
    practice using the debugger with it.
  4. Adapt your code to be able to send a variable string.
    This will be invaluable for future work! 
    Keep practicing with that debugger...
  5. Still on the one Nucleo board, add code to be able to receive on the UART via the ST-Link VCP from a terminal on your computer.
  6. Still on the one Nucleo board, adapt your receiving code to check for a specific message; when that is  received, light the LED.
    Test this code 
    via the ST-Link VCP from a terminal on your computer.
  7. By now you should have code on one Nucleo board that can send a message, recognise a received message, and light the LED - now you are ready to load this code onto another (identical) Nucleo board, and connect the two together.

See this thread for more learning resources - with a focus on STM32:

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719485

 

Some links here on testing/debugging serial comms:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/706966/highlight/true#M49