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

Thanks a lot @Pavel A. For the detailed explanation. I'll try doing the things you mentioned and see if I'm able to find where the thing is going wrong and then get back to you!

@Pavel A. I was able to debug the code using ITM and found that the data was not getting received as expected. But after changing the logic like this it started working.

if (HAL_UART_Receive(&huart1, &rx_data, 1, HAL_MAX_DELAY) == HAL_OK) {
		HAL_UART_Transmit(&huart1, &rx_data, 1, HAL_MAX_DELAY);
		if(rx_data == 'F'){
			HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);
		}
		if(rx_data == 'S')
		{
			HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);
		}

Thanks a lot everyone for your inputs! My issue got resolved!