Forum Discussion
Altera_Forum
Honored Contributor
13 years agoUART on DE2
Hi, I'm using DE2 (old kit) and my application has a UART to exchange data with PC. I'm using the kit's RS232 connection (not the JTAG). I created the system (including the UART at 9600bps) in Qsys a...
Altera_Forum
Honored Contributor
13 years agoThis is my code:
# include <stdio.h> # include <string.h> int main () { char* msg = "Detected the character 't'.\n"; FILE* fp; char prompt = 0; fp = fopen ("/dev/rs232", "r+"); //Open file for reading and writing if (fp) { while (prompt != 'v') { // Loop until we receive a 'v'. fprintf(fp, "Entered while.\n"); 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; } I have made some changes after I wrote the post and now I'm able to send and receive characters. Although, it isn't suitable for my application to use polling to receive characters, so I need to implement interrupt at least for reception, but I have no idea how to do this. Any tip?