Skip to main content
Visitor II
June 24, 2024
Question

UART2 VCP L432KC

  • June 24, 2024
  • 3 replies
  • 914 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.

    3 replies

    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

    Graduate II
    June 24, 2024

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

    Graduate II
    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
    }

     

    Super User
    June 25, 2024

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