串口液晶屏在工控机上测试程序可行,到开发板上不行?
串口液晶使用的是SLCM19264
工控机系统为unbuntu10.04,编译器gcc
开发板为arm的xm31平台,交叉编译器arm-none-linux-gnueabi-gcc
程序如下
#include
#include
#include
#include
#include
#include
#include
#include
#include
int fd;
static void uart_set(int fd, int baud, int databits, char parity, int stopbits)
{
struct termios opt;
tcgetattr (fd, &opt);
opt.c_cflag |= (CLOCAL | CREAD);
printf("ispeed = %d\n", cfgetispeed(&opt));
printf("ospeed = %d\n", cfgetospeed(&opt));
switch (baud)
{
case 9600:
cfsetispeed(&opt, B9600);
cfsetospeed(&opt, B9600);
break;
case 19200:
cfsetispeed(&opt, B19200);
cfsetospeed(&opt, B19200);
break;
case 57600:
cfsetispeed(&opt, B57600);
cfsetospeed(&opt, B57600);
break;
case 115200:
cfsetispeed(&opt, B115200);
cfsetospeed(&opt, B115200);
break;
default:
cfsetispeed(&opt, B115200);
cfsetospeed(&opt, B115200);
break;
}
opt.c_cflag &= ~CSIZE;
switch (databits)
{
case 7:
opt.c_cflag |= CS7;
break;
case 8:
opt.c_cflag |= CS8;
break;
default:
printf ("Unsupported data size\n");
return;
}
switch (parity)
{
case 'n':
case 'N':
opt.c_cflag &= ~PARENB;
break;
case 'o': // odd
case 'O':
opt.c_cflag |= (PARODD | PARENB);
//opt.c_iflag |= INPCK;
break;
case 'e': // even
case 'E':
opt.c_cflag |= PARENB;
opt.c_cflag &= ~PARODD;
//opt.c_iflag |= INPCK;
break;
case 's': //space
case 'S':
opt.c_cflag &= ~PARENB;
opt.c_cflag &= ~CSTOPB;
break;
default:
printf ("Unsupported parity\n");
return;
}
switch (stopbits)
{
case 1:
opt.c_cflag &= ~CSTOPB;
break;
case 2:
opt.c_cflag |= CSTOPB;
break;
default:
printf ("Unsupported stop bits\n");
return;
}
opt.c_cc[VTIME] = 0;
opt.c_cc[VMIN] = 0;
// set raw input
opt.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
opt.c_iflag &= ~(INLCR | ICRNL | IGNCR);
// set raw output
opt.c_oflag &= ~OPOST;
opt.c_oflag &= ~OLCUC;
opt.c_oflag &= ~ONLRET;
opt.c_oflag &= ~ONOCR;
opt.c_oflag &= ~OCRNL;
tcsetattr (fd, TCSANOW, &opt);
printf("ispeed = %d\n", cfgetispeed(&opt));
printf("ospeed = %d\n", cfgetospeed(&opt));
tcflush(fd, TCOFLUSH);
tcflush(fd, TCIFLUSH);
}
void Display_info()
{
printf("%s\n", FUNCTION);
int ret;
char *s = "?";
char c = 0x3F;
char c2 = 0x0D;
char c3 = 0x72;
char c4 = 0x65;
char c5 = 0x73;
ret = write(fd, &c, 1);
ret = write(fd, &c, 1);
ret = write(fd, &c, 1);
ret = write(fd, &c2, 1);
printf("write ok\n");
//ret = write(fd, "???", 3);
//ret = write(fd, "\r", 1);
usleep(DISPLAY_DELAY);
}
int main(int argc, char **argv)
{
int nread,i;
int nwrite;
unsigned char buff[1024] = {0};
if (argc == 1) {
if((fd=open_port(1, "/dev/ttyS0"))<0) {
perror("open_port error");
return -1;
}
} else {
if((fd=open_port(1, argv[1]))<0) {
perror("open_port error");
return -1;
}
}
printf("fd = %d\n", fd);
uart_set(fd, 19200, 8, 'n', 1);
while(1) {
//Display_Menu();
Display_info();
usleep(2000000);
printf("ready read\n");
nread = read(fd,buff,1024);
printf("read ok\n");
printf("nread=%d,%s\n",nread,buff);
}
close(fd);
return 0;
}
状况是运行程序后,write没有写进去,read返回nread = 0(类似没有在串口接入任何东西的状态)
已经做过的测试:
1.应用程序
用已有的程序实验,在工控机上无问题(液晶屏,应用程序无错)
2.驱动
短接2,3,发现输出,输入无问题(接口,驱动无错)
怀疑:连线问题
结果:线序错了
3.还是无反应
链接液晶屏端串口rt端口
自测有效,排除线的问题。
请问哪位大神知道还有可能是什么问题导致的现在这种情况???