cancel
Showing results for 
Search instead for 
Did you mean: 

UART2 VCP L432KC

Abijith
Associate II

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.

 

 

 

 

4 REPLIES 4
Roger SHIVELY
ST Employee

Hello @Abijith 

 

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

 

Regards,

Roger

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
Up vote any posts that you find helpful, it shows what's working..

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
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

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