- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page