cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 receiving and transmitting data at the same time

ahmetefek12
Associate II

50B908E4-5C3C-4EBB-894F-C3046F81B6C3.png

AE9DE369-1ED0-4071-83C6-742A007915F1.jpeg

Hello, I am new to the stm32 world.

I'm trying to use my stm32f103c8t6 board as an intermediary to enable communication between the computer and arduino.

The project is simply based on receiving a message from the computer, and the STM32 sending a different message package to Arduino according to the incoming message.

That is, receive and transmit operations must occur simultaneously.

For this, at first I was receiving data via USB CDC and transmitting data via UART and I was successful. But for reasons beyond my control, I need to use a communication method other than USB-CDC.

Even though I tried to use uart for data exchange, I was not successful, there is an example code I shared at the image (pink ones are message I sent, black ones message I get) I would appreciate it if you could tell me the changes I should make for this process or the protocols you recommend me to use.

 

 

3 REPLIES 3
Karl Yamashita
Lead III

This tutorial shows how to receive and transmit using DMA with idle.

https://github.com/karlyamashita/Nucleo-G431RB_Three_UART

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

Try to avoid blocking functions like HAL_UART_Transmit() in interrupt / call-back context.

Buffer all incoming data and don't create dependency on a single buffer and synchronization of the first byte.

Your reception pattern is not intuitive and your input demo doesn't really convey what it's supposed to do vs what it's actually doing.

It's receiving 6 bytes? Looking for a S****F* pattern? Is it supposed to resynchronize?

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

Message packets from the computers serial terminal to the stm32 are in 5-digit SXXXF (e.g. S123F) format. What the stm32 needs to do is to transmit the only 4th digit of the message to the next device (in this case, Arduino). I also tried using the HAL_UART_Transmit_IT function, but this time no data was transmitted.