Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Using UART controller of SOPC while testing serial interfaces

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?

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.