菜鸟求助!!!为什么只能发送不能接收- -#

yko_L 2011-08-10 10:44:49
我正在学习android的系统开发,想写一个linux程序实现串口和其他设备通信,但搞了几个星期都不知道串口2只能发送不能接收的原因?各位大虾,请帮小弟一把。我用的芯片是imx515。
我测试过,硬件上没有问题,我在RXD引脚上可以看到信号,至于串口驱动应该是没有问题的。所以我一直怀疑是我的设置有问题。请帮我看一下问题出在哪。


#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/time.h>

int main(int argc, char **argv)
{
int fd;
char *dev ="/dev/ttymxc1";
struct termios termios;
char rbuf[256] = "";
char wbuf[256] = "";
int nread, nwrite;
int i;

printf("==== START ====\n");
fd = open(dev, O_RDWR | O_NOCTTY);

if(fd < 0)
{
printf("open %s fail!\n", dev);
return 0;
}

printf("open %s success!\n", dev);

tcgetattr(fd, &termios);
bzero(&termios, sizeof(termios));

termios.c_cflag = B115200|CS8|CLOCAL|CREAD;
termios.c_iflag = IGNPAR | IXON | IXOFF | IXANY;
termios.c_oflag = 0;
termios.c_lflag = 0;
termios.c_cc[VTIME] = 0;
termios.c_cc[VMIN] = 0;

tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &termios);


printf("====MISSION START====\n");
nwrite = write(fd, "====MISSION START====", 21);

printf("==== READ TEST ====\n");
while(1)
{
nread = read(fd, rbuf, 10);
if(nread > 0)
{
printf("====MISSION COMPLETE!====\n");
break;
}
}

printf("==== THE END ====\n");
close(fd);
return 0;
}
...全文
91 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yko_L 2011-08-22
  • 打赏
  • 举报
回复
结帖吧。问题已经解决了,虽然不知道具体的原因,但我换了另外一个版本的内核之后就好了。
changing_better 2011-08-11
  • 打赏
  • 举报
回复
首先你先自环看看,自己的收发直接相连,这样不管你串口如何设置,你都可以接收到正确的帧数据。然后看下你的驱动的读操作是如何实现的,看下调用read返回值的情况。

21,616

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧