QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2150|回复: 0

关于串口驱动编程问题,挺急!请帮助!!!!

[复制链接]
发表于 2006-9-4 21:07:34 | 显示全部楼层 |阅读模式
小第最近在做LINUX串口驱动编程。平台是S3C2410。我有个外设,是个串口设备。我运用了LINUX系统自带的SERIAL_8250.C文件,其实就是一个16C550兼容的设备驱动。寻址16C550设备这些都没有问题了。串口设备驱动也加载并且注册了。看来一切都很顺利。但是在LINUX下编写了一个串口测试程序,主代码大致如下:
int main(int argc, char **argv)
{
        int fd;
        int nread;
        char buff[512];
        char *dev ="/dev/ttySA0";
        fd = OpenDev(dev);
        if (fd>0)
{
                printf("set speed\n");
                    set_speed(fd,115200);
}
        else
        {
                printf("Can't Open Serial Port!\n");
                exit(0);
        }
          if (set_Parity(fd,8,1,'N')== FALSE)
          {
                    printf("Set Parity Error\n");
                    exit(1);
          }
          while(1)
          {
                   while((nread = read(fd,buff,512))>0)
                   {
                              printf("\nLen %d\n",nread);
                              buff[nread+1]='\0';
                              printf("\n%s",buff);
                    }
          }
            //close(fd);
            //exit(0);
}


其中 set_Parity()函数实现如下:
int set_Parity(int fd,int databits,int stopbits,int parity)
{
        struct termios options;
if  ( tcgetattr( fd,&options)  !=  0)
  {
          perror("SetupSerial 1");
          return(FALSE);
  }
...................
}
运行起来后,串口设备打开成功,但是调用  tcgetattr( fd,&options) ,系统却老是报告 SetupSerial 1 :Input/output error
真不知道是什么原因。我使用2410自己的串口驱动设备,是正常的。
请知道原因的朋友们帮我分析分析。不胜感激啊!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-13 13:26 , Processed in 0.071891 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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