Skip to main content
Explorer
April 19, 2024
Question

Handling UART receive

  • April 19, 2024
  • 1 reply
  • 780 views

I'm looking into creating a splashscreen and handling the uart responses. How can I wait for the input without consistently sending the response messaging. I'm unsure how to handle responses from the uart receive line.

 

 

enum splashscreen_response_type
{
 TEST_RESPONSE_VALID,
 TEST_RESPONSE_INVALID,
 TEST_RESPONSE_UNKNOWN,
 TEST_RESPONSE_MAX
};



int bootup_disp()
{
 int test_type_response = TEST_RESPONSE_UNKNOWN;
 char input[100]; // Buffer to hold the user input
 int processed_input;
 int chosen_test;
 int resp_buff[1];

 
 HAL_UART_Transmit(&hlpuart1,(uint8_t*)"USER CHOICE TYPE 1 for test:", sizeof("USER CHOICE TYPE 1 for test:"), 500);
 HAL_UART_Transmit(&hlpuart1,(uint8_t*)"TYPE USER CHOICE:", sizeof("TYPE USER CHOICE:"), 500);

 do{
 HAL_UART_Receive(&hlpuart1,splash_resp_buff, 1,500);
 
 if(resp_buff == 1)
 {
 HAL_UART_Transmit(&hlpuart1,(uint8_t*)"CORRECT CHOICE", sizeof("CORRECT CHOICE"), 500);
 test_type_response = TEST_RESPONSE_VALID);
 
 }
 else
 {
 HAL_UART_Transmit(&hlpuart1,(uint8_t*)"INCORRECT CHOICE", sizeof("INCORRECT CHOICE"), 500);
 }
 }
 while (test_type_response != TEST_RESPONSE_VALID);*/

 HAL_UART_Transmit(&hlpuart1,(uint8_t*)splash_resp_buff, sizeof(splash_resp_buff)-1, 500);

 

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    April 19, 2024

    Your code accepts any input as valid and no user input as invalid. You should consider no user input as a NO-OP and not as a incorrect choice.

    mm.51Author
    Explorer
    April 19, 2024

    What do you mean by NO-OP ? So are you saying I should accept no response as incorrect ? What would you recommend doing ?