cancel
Showing results for 
Search instead for 
Did you mean: 

Black pill serial communication not working!

zeus
Associate II

Hey guys!

I'm trying to run the eaxmple found in this link: https://deepbluembedded.com/stm32-serial-port-uart-with-usb-ttl-converter-pc-interfacing/

I'm able to read the data from MCU serially, but when I write, the GPIO is not getting toggled. I've configured the MCU as described. I'm using blackpill v3 board. What I suspect is there is an issue with type conversions. But not sure. It would be very helpful if someone can help me with this. 

Thanks in advance!

21 REPLIES 21

I was assuming the LED pin is set to high on reset, and that either condition is supposed to set it low (which turns on the LED). If not, than Chris21's answer may be right on the money.

 

I don't have a debugger. I'm using the serial transmit to try printing the value. But still no luck.

You should get one.

 

if you have serial OUT working, you can use that to send back the received character and examine it that way.

You can also use serial OUT to verify whether the "if" body is being executed.

 

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);

Even If I do the above It's not working!

Thanks for your response!

I tried the same code with Nucleo-H723ZG Development Board. Still no luck :(

zeus
Associate II

Okay, So I tried debugging the code with debugger. I'm able to see that the if statement is not satisifed. I'm new to STM32 and I'm not sure how to print the values on debugger console. Can anyone please help me with that? Also, check the image for reference:

zeus_0-1725726878648.png

 

Pavel A.
Evangelist III

@zeus So are your questions now about Nucleo-H723ZG (with genuine ST-LINK on-board) or black pill? 

Well, my question is how to make the uart code work as I'm not sure what am I missing. I'm using Nucleo-H723ZG (with genuine ST-LINK on-board) to debug the code as I don't have sepate debugger to test on black pill. So, how can I print the variables in the debugger console while using the st-link onboard?

Techn
Senior III

Have you checked if you have connected all signal grounds properly? to test rs232 you can do loopbak. Do loopback towards data source and see if you get back what you transmit. 

If you feel a post has answered your question, please click "Accept as Solution".
Techn
Senior III

What happens if you get any other symbol in the serial line? First chek if your processor gets anything at all, later you can start filtering and processing 

You can  try HAL_GPIO_TogglePin

 

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

@zeus 

how can I print the variables in the debugger console while using the st-link onboard?

Two ways. (But none of them prints to the debugger console window like on your screenshot).

1. The onboard ST-LINK usually has internal USB to serial adapter, so called "VCP". On the STM32 side it is connected to one of U(S)ARTs. See your Nucleo user guide to know which UART it is, on which pins.

Then just initialize this UART in "asynchronous mode" and send your output. On the PC side use your favorite terminal program such as Teraterm. CubeIDE also has a serial terminal built in, but IMHO it is less convenient.

2. The onboard ST-LINK can use STM32 feature called ITM. It is basically a sub-channel of the debugger connection that you can use to send output. You need to enable it in the debugger options. The output will go to a special window of CubeIDE or other debugger: "ITM console" or whatever.  Like the former, this does not need a separate cable, just the debugger USB cable plugged in. Very convenient.

Please take your time, check the examples, CubeIDE user manual, ST app. notes and your favorite search engine.

zeus
Associate II

@Techn I did check the signal grounds and everything is proper. I also tried the HAL_GPIO_TogglePin. It's working fine, also the processor is able to transmit data via UART and I was able to get it printed on CoolTerm.