Forum Discussion
Altera_Forum
Honored Contributor
20 years agoHow to tell there is data from UART?
Hi
Browsing through Altera documentation suggests I should be using the HAL with a UART. So using the HAL how do I determine if there is data available from the UART before calling getchar()? I need my system to be doing other stuff and can't have it block while waiting for the UART to receive data. I can see I have to use the fast version of the driver so that the UART operates under interrupts but I can't see an equivalent to the old kbhit() function. Ta, Mike3 Replies
- Altera_Forum
Honored Contributor
Just an idea, can you fiddle with the driver to be able to look at the pointers for the receive buffer? Maybe you can work out a function like kbhit then.
Stefaan - Altera_Forum
Honored Contributor
open device uart in non blocking mode:
static int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN .. fdterm = open("/dev/uart1", O_RDWR | O_NONBLOCK | O_NOCTTY); .. reading is done by .. res=read(fdterm,uart1_tempbuff,sizeof(uart1_tempbuff)-1); if(res>0) { ... we have received some bytes } - Altera_Forum
Honored Contributor
Fischer
Thanks for your reply. I managed to work it out for myself but it is nice to have confirmation from a expert that I am doing the right thing. Mike