Forum Discussion
Altera_Forum
Honored Contributor
12 years agonios rs232 uart reads only last byte
Hi, I'm using rs232 uart in nios. I'm using the open and read functions to recive data from the uart. I'm using the serial port monitor in order to send data on rs232 from the computer to t...
Altera_Forum
Honored Contributor
12 years agoHere is an example to detect some characters:
char* msg = "Detected the character 't'.\n"; FILE* fp; char prompt = 0; fp = fopen ("/dev/uart1", "r+"); //Open file for reading and writing if (fp) { while (prompt != 'v') { // Loop until we receive a 'v'. prompt = getc(fp); // Get a character from the UART. if (prompt == 't') { // Print a message if character is 't'. fwrite (msg, strlen (msg), 1, fp); } } fprintf(fp, "Closing the UART file.\n"); fclose (fp); } return 0;