Skip to main content
Explorer II
May 30, 2022
Solved

UART/USART Does not Work

  • May 30, 2022
  • 5 replies
  • 12684 views

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.

    This topic has been closed for replies.
    Best answer by gbm

    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.

    5 replies

    Graduate II
    May 30, 2022

    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.

    akoluacikAuthor
    Explorer II
    May 31, 2022

    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.

    Graduate II
    May 31, 2022

    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.

    Visitor II
    May 31, 2022

    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!!

    akoluacikAuthor
    Explorer II
    May 31, 2022

    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.

    Visitor II
    May 31, 2022

    0693W00000NqvzHQAR.png

    Visitor II
    May 31, 2022

    Did you change the timeout?

    what is the board that you are using?

    akoluacikAuthor
    Explorer II
    June 1, 2022

    I am using STM32F746NG Discovery board. I changed timeout to 100 as you said, and tried more different values, i.e., HAL_MAX_DELAY. But still does not work.

    My RCC setting is that I enabled HSE and configured max frequency value, which 216 kHz.

    Graduate II
    June 3, 2022

    MHz, kHz... The units doesn't matter, do they? ;)

    gbmAnswer
    Graduate
    June 1, 2022

    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.

    akoluacikAuthor
    Explorer II
    June 2, 2022

    Thank you sooo much. This solves my problem. I have a question, how did you determine that the correct ones are PA9 and PB7? I looked at the datasheet more times but I couldn't determine it.

    Graduate II
    June 3, 2022

    Datasheet, reference manual etc. are for a microcontroller. Board features are documented in board's user manual and schematic.

    Graduate
    June 1, 2022

    Hi @Anıl Koluaçık​ 

    Try to use CDC_Transmit_FS function as you are using the COM Port

    Graduate II
    June 1, 2022

    Writing "u" instead of "you" and inability of splitting the thought to sentences really is an indicator...