繁体   English   中英

为什么我的串口通讯不起作用?

[英]Why is my serial communication not working?

我查看了DE2的手册 (第177页),据我所知,应该可以通过putty和usb-to-serial电缆进行串行通信,因此我从手册中获取程序:

/* 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

然后当我连接终端程序(putty串行连接)时,它没有连接。 我究竟做错了什么? 我试图将projet i / o改为uart,但这并没有帮助。 你能帮助我吗?

如何调试串行通信:

使用9针串行电缆并将跳线针脚2和3放在一起。 您可以使用回形针或任何方便的东西。 引脚2和3是TX和RX。 如果将它们连接在一起,计算机将接收从计算机发送的任何命令。 你创建了一个串行环回!

打开Putty,尝试连接到您的串行电缆。 点击键盘上的任意键。 波特率和事情并不重要,因为它是一个环回。

如果您在终端上看到收到的字符,则串行电缆可以正常工作! 如果没有,您的电缆或腻子有问题。 我在过去通过串行通信遇到过putty的问题。 如果您有Putty未连接的问题,请尝试下载Tera Term

或者找到串口线的新驱动程序! 祝好运。

在Linux中,我会做以下事情。

fp = fopen ("/dev/ttyS0", "r+"); //Open file for reading and writing

要么

寻找ttyS1; 如果正在使用ttyS0。

fp = fopen ("/dev/ttyS1", "r+"); //Open file for reading and writing

dmesg知道你附加了哪个确切的设备。

$tail -f /var/log/messages

对于USB-serial,它可能是

的/ dev / ttyUSB0; 可以使用/ var / log / messages查找确切的数字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM