Forum Discussion
Altera_Forum
Honored Contributor
15 years agoHi,
maybe you could use the HAL file system as described in the embedded peripherals ip user guide / uart core./* A simple program that recognizes the characters 't' and 'v' */# include <stdio.h># include <string.h>
int main ()
{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;
}It's not an example how to transfer 32 bit, but it shows you how to open a device with the HAL file system and sending/receiving data. I would recommend to use something like fwrite(&buffer32bit,4,1,fp) and fread(&buffer32bit,4,1,fp). I never tried it, but I guess it should work. But I also would recommend to use the uart-registers directly (as you did in your example) and read byte by byte. Regards