Forum Discussion
Altera_Forum
Honored Contributor
18 years ago --- Quote Start --- originally posted by arrive@Mar 12 2007, 12:41 PM there are a syntax error in the posted code, so the following code is used:
#include <stdio.h># include <string.h>
int main()
{
file* fp;
char prompt = 0;
fp = fopen("/dev/uart", "r+");
if(fp){
printf("uart open. \n");
}
else{
printf("uart closed. \n");
return 0;
}
fprintf(fp, "uart\n");
while(prompt != 'v'){
prompt = getc(fp);
printf(" \n", prompt);
}
fclose(fp);
return 0;
}
(btw, usually "\r\n" is needed in hyperterminal for newline)
i compiled the hardware in quartus ii 6.1 and software in nios ide and it works fine, outputing to the uart and receiving characters from there too.
assuming the "uart open." message can be seen so the program should be running correctly, there could be a few causes for the error:
1. make sure the name "dev/uart" matches the uart name in sopc builder, i.e., "uart" is the name in sopc builder.
2. connect to the correct uart port. usually a computer has com1 and com2, so make sure the right one is chosen in hyperterminal. (if you are using the pc for testing)
3. make sure the uart setting in sopc builder matches the settings in hyperterminal, such as parity, data bits, stop bit, flow control, etc.
please let me know if the above doesn't help and provide more information, such as the program output, sopc ptf file, etc.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22235)</div> --- Quote End ---