This 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?