天嵌 ARM开发社区

 找回密码
 注册
查看: 3121|回复: 9

有关2440串口的使用问题

[复制链接]
fjpmbb 发表于 2010-6-29 15:32:22 | 显示全部楼层 |阅读模式
由于现在手上没有串口扩展板。我现在想使用TQ2440的控制台的串口,不知道要在linux的设置中改哪些地方。就是串口0不在作为控制台的打印信息用。
 楼主| fjpmbb 发表于 2010-6-29 15:33:58 | 显示全部楼层
自己还是先顶一顶
:)
亚瑟王 发表于 2010-6-29 22:01:48 | 显示全部楼层
修改文件系统的/etc/inittab文件,将askfirst那句话删掉。修改uboot的启动参数,将console=ttySAC0改为console=tty0(反正不等于ttySAC0)即可,然后用telnet访问开发板,调用串口初始化程序吧。
 楼主| fjpmbb 发表于 2010-6-30 10:54:34 | 显示全部楼层
我按照你说的那些操作进行了试验,现在控制台是没有发信息了 但是我现在用我的一个程序,打开串口0
fd = open("/dev/tqc2440_serial0",O_RDWR | O_NOCTTY | O_SYNC);
printf("fd is %d\n",fd);
这个fd永远是“-1”,为什么呢?

我把我的代码贴上面来


//通过板子向PC发数据的程序:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>



int main()
{
//char buff[8]={0x68,0x01,0x25,0x23,0x45,0x78,0x26,0x16};
char buff[8]={"Good!\n"};
int fd,c,res,nsize = 0;
int i=0;
struct termios oldtio,newtio;
//fd = open("/dev/tqc2440_serial1",O_RDWR | O_NOCTTY | O_SYNC);
while(1)
{
//fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_SYNC);
fd = open("/dev/tqc2440_serial0",O_RDWR | O_NOCTTY | O_SYNC);
printf("fd is %d\n",fd);
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_oflag &= ~OPOST;
newtio.c_lflag = 1;
cfsetispeed(&newtio,B115200);
cfsetospeed(&newtio,B115200);
tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
nsize=write(fd,buff,8);
fcntl(fd,F_SETFL,FNDELAY);
if(nsize<0)
{
perror("Write wrong");
return;
}
tcsetattr(fd, TCSANOW, &oldtio);
close(fd);
sleep(1);
}
}
 楼主| fjpmbb 发表于 2010-6-30 10:57:52 | 显示全部楼层
这个就是执行的结果
fd is -1
Write wrong :Bad file descriptor
 楼主| fjpmbb 发表于 2010-6-30 13:44:37 | 显示全部楼层
自己先顶一顶 我现在还没有解决我现在 把fd = open("/dev/tqc2440_serial0",O_RDWR | O_NOCTTY | O_SYNC);
改成tqc2440_serial1,tqc2440_serial2 结果也还是一样的
这个我就纳闷了 我根本就没有其他的应用程序对上面所列的串口对其进行占用
为什么也会出现
fd is -1
Write wrong :Bad file descriptor
:)
 楼主| fjpmbb 发表于 2010-6-30 17:51:26 | 显示全部楼层
亚瑟王 我等着你的答复
亚瑟王 发表于 2010-6-30 21:52:30 | 显示全部楼层
论坛中提供了串口测试程序的,你下载了试试。
testh 发表于 2010-8-20 21:53:29 | 显示全部楼层
你看一下/dev/tq2440_serialx的权限,测试程序是否是用root身份运行的,当有返回值的时候最好打印出系统的错误信息,我当时在这里卡住了很久,忽略了看系统的提示信息
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-6 06:05 , Processed in 1.025325 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表