Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21586 Discussions

A UART question related to character READ

Altera_Forum
Honored Contributor II
1,081 Views

Hello, 

I'm new to to this forum and here's a UART related question.  

 

Im using a polling loop like this one to read a byte from the UART register: 

 

1. status = IORD_ALTERA_AVALON_UART_STATUS(UART_DEBUG_BASE); 

if (status == 0x60) then goto step# 2 else go back to step# 1 

 

2. ch = (char)IORD_ALTERA_AVALON_UART_RXDATA(UART_DEBUG_BASE);  

 

3. What do I do here to reset something in the UART before going back to step# 1 so as NOT to get the last character that I just read in step# 2?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
407 Views

Try this: 

int uart_read(int base, char *ptr, int len, int flags){ int block; unsigned int status; block = 1;//!(flags & O_NONBLOCK); do{ status = IORD_ALTERA_AVALON_UART_STATUS(base); /* clear any error flags */ IOWR_ALTERA_AVALON_UART_STATUS(base, 0); if (status & ALTERA_AVALON_UART_CONTROL_RRDY_MSK){ ptr = IORD_ALTERA_AVALON_UART_RXDATA(base); if (!(status & (ALTERA_AVALON_UART_STATUS_PE_MSK | ALTERA_AVALON_UART_STATUS_FE_MSK))){ return 1; } } }while (block); return 0; }  

 

It's not a completed function but I believe it illustrates what you're missing.
0 Kudos
Reply