Skip to main content
Associate II
June 24, 2024
Question

UART2 VCP L432KC

  • June 24, 2024
  • 4 replies
  • 940 views

while (1)

{

/* USER CODE END WHILE */

if (HAL_UART_Receive(&huart2, data, 10, 100) == HAL_OK) {

 

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);

HAL_Delay(200);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);

HAL_Delay(200);

}

/* USER CODE BEGIN 3 */

}

 

This is my code to check if I am sending any data from Putty/Realterm/Docklight to UART2 and then blinking the in built LED. What are some reasons this might not be working? I tried this in interrupt mode as well.

 

 

 

 

This topic has been closed for replies.

4 replies

Roger SHIVELY
ST Employee
June 24, 2024

Hello @Abijith 

 

This post has been escalated to the ST Online Support Team for additional assistance.  We'll contact you directly.

 

Regards,

Roger

Tesla DeLorean
Guru
June 24, 2024

Can't we please just have FAE's, or whomever, just come and answer simple questions directly?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
June 25, 2024

Well it's going to repeatedly fail if you don't get 10 characters in 100 ms, like you pressing continuously.

Then slacking off for 400 ms when no reception can occur and you'll get overrun or other errors due to inattention.

You'd do better with a simple echo back

 

while(1)
{
 if ((USART2->ISR & USART_ISR_RXNE) == 0) // Wait for Char
 {
 if (USART2->ISR & USART_ISR_ORE) // Overrun Error
 USART2->ICR = USART_ICR_ORECF;
 if (USART2->ISR & USART_ISR_NE) // Noise Err
 USART2->ICR = USART_ICR_NCF;
 if (USART2->ISR & USART_ISR_FE) // Framing Error
 USART2->ICR = USART_ICR_FECF;
 }
 else // RXNE
 USART2->TDR = USART2->RDR; // Read Char, Echo
}

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
June 25, 2024

@Abijith The timeout 100 ms is probably too short. Try something like 10000 ms (10s) or indefinite.