USB console usart stdio : how to get char in 'no blocking' mode?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all, I have found this example to read data from console:

 

char in_char;

scanf("%c", &in_char);
if (in_char) {
   // data read is ok....
}

 

It is working fine, but scanf() is blocking!

Any idea to have an easy implementation for a 'non blocking' code?

Last Edited: Sun. Jun 12, 2022 - 10:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

of course it works also with the standard getchar(), but it is still blocking...

char in_char = getchar();

 

the stdio use the SERCOM5, so I tried a 'dirty' solution: read data as a normal serial line. It works. Now I get the char when it is available, but it is not blocking....

if (usart_read_wait(&cdc_uart_module, &temp) == STATUS_OK) {
     printf("Console : %c\n", temp);
}

 

Any side effect?

Can I run in trouble?