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

Using UART controller of SOPC while testing serial interfaces

Altera_Forum
Honored Contributor II
894 Views

Hi, 

 

For checking my serial interface in loopback mode, I used the controller provided in SOPC builder and used the C code provided in datasheet of UART core -  

# include <stdio.h># include <string.h> 

int main () 

char* msg = "CCU\n"; 

FILE* fp; 

char buff[3]=""; 

char prompt=0; 

int i=0; 

fp = fopen ("/dev/uart1", "r+");  

if (fp) 

//while(1)  

fwrite (msg, strlen (msg), 1, fp); 

 

while (prompt != 'U') 

{  

prompt = getc(fp); 

buff[i] = prompt; 

printf("%c", prompt); 

i++; 

 

if(buff[0] == 'C' && buff[1] == 'C' && buff[2] == 'U') 

printf("\nSuccess"); 

else 

printf("\nFailed"); 

return 0; 

 

The problem is that if getc() is not getting any value, then the code gets hanged. Is there a way out to avoid this problem? According to my knowledge, i the code should proceed on even if there is no data. Can someone help me in this regard?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
223 Views

Maybe you can look at the rrdy bit in the status register. This bit is set to one if data is transfered. Otherwise it is set to zero. But then you could have the problem that data could be lost. If you have Quartus 9 there is an UART with build in fifo. There you can look if this fifo is filled and then you can read it, otherwise you are doing something else.

0 Kudos
Reply