【发布时间】:2013-10-02 03:23:01
【问题描述】:
我查看了 DE2 的 manual(第 177 页),据我所知,它应该可以进行串行通信,例如通过腻子和连接到板上的 USB 到串行电缆,所以我采取手册中的程序:
/* 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 JTAG UART.
if (prompt == 't')
{ // Print a message if character is 't'.
fwrite (msg, strlen (msg), 1, fp);
}
if (ferror(fp))// Check if an error occurred with the file pointer
clearerr(fp); // If so, clear it.
}
fprintf(fp, "Closing the JTAG UART file handle.\n");
fclose (fp);
}
return 0;
}
我尝试将它作为 Nios2 硬件运行,但是当我将 std i/o 配置为使用 uart 时收到此消息
nios2-terminal: can't open uart: No such file or directory
然后当我连接终端程序(腻子串行连接)时,它没有连接。我究竟做错了什么?我尝试在项目的特性中将 std i/o 更改为 uart,但这并没有帮助。你能帮帮我吗?
【问题讨论】:
-
请先缩进你的代码。
-
你正在迭代你正在修改的文件..
-
第一次尝试:
"/dev/uart1"在 shell 上会显示文件名...也将你的代码写成$sudo ./exename
标签: c serial-port fpga uart nios