cancel
Showing results for 
Search instead for 
Did you mean: 

UART/USART Does not Work

akoluacik
Senior

I would like to transmit data via USART and read the data sent to computer via a terminal(I have tried Putty and Real Term so far). To that end, I activate 0693W00000NqsasQAB.pngMy USART configuration is seen as above. I also wrote the code below:

uint8_t myTxData[13] = "Hello World\r\n";
while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
 	  HAL_StatusTypeDef res = HAL_UART_Transmit(&huart1, myTxData, 13, 10);
	  if(!res) {
		  HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_1);
		  HAL_Delay(1000);
	  }
  }

Note that I only put here inside the while loop. The other statements were generated by CubeMX.

Normally my code sends data to my pc if res is true, in other words, if it is HAL_OK, and also toggles the LED. Since it couldn't see the data in the terminal, I changed the condition in if statement, and saw that the led is toggled in each second. Therefore, I concluded that my USART channel does not work. What's the issue?

Thx for your help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

Your program runs on STM32F746, not on ST-Link CPU (STM32F103, which uses its PA2 and PA3 to connect to F746). The schematics of Discovery board shows the pins used in F746 for UART VCP connection are PA9 and PB7, which are USART1 TX and RX pins.

View solution in original post

16 REPLIES 16

This doesn't show any of the initialization code for the USART, clocks and pins.

Check it is using the right pins.

Check pins with a scope.

Check bit timings of 'U' pattern, confirm baud rate settings.

The USART TX pin uses CMOS levels, this is not compatible with RS232 levels.

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

Thanks for your response, but unfortunately I understand nothing. May I ask you to give th more details about the steps plase?

In addition, AFAIK, sending a message to a terminal is fairly easy with UART? Am I wrong? What action do I take if USART TX pin uses CMOS level? And I am not using RS232, and I already disabled it.

Thx for your response.

Ax111_
Associate II

What is see is your timeout period is 10, change that to 100.

Next is check the baudrate on your serial terminal, it should be 115200.

It must work now!!

Unfortunately, that doesn't work as well. I checked that the baud rate of the serial terminal is 115200, too.

Thx your response. I am pleased if you have another way.

Ax111_
Associate II

Did you change the timeout?

what is the board that you are using?

0693W00000NqvzHQAR.png

what is your RCC setting?

No details on which STM32 you are using, the board or the pins involved.

Code provided so far is superficial. Issue likely not timeout related, should still see 10 or so characters.

Perhaps look at other Cube/HAL examples, where information is less hidden.

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

I am sorry for these missing parts. I am newbie to both embedded systems and the forums.

I am using STM32F746NG discovery board. I tried all USART channels but I still got nothing.0693W00000NqzEZQAZ.pngThe image above is a part of the schematic of my board. I activated PA2 and PA3 pins for UART TX and RX pins, respectively. I am not sure however if it is correct.