Altera_Forum
Honored Contributor
16 years agoUsing 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?