串口液晶屏在工控機上測試程序可行,到開發板上不行?
串口液晶使用的是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端口
自測有效,排除線的問題。
請問哪位大神知道還有可能是什麼問題導致的現在這種情況???
7,工控機自發自收,
arm版自發自收都ok
8.更換開發板為rs232的,開發板與工控機收發數據正常
開發板與液晶屏依舊無反應(/dev/ttymxc2)
開發板rs電壓:-3.0~3.0 :失敗和電壓值無關
9.萬萬沒想到,最終是屏的問題,換了塊就好了。
差異:原來的屏程序輸入後反應延遲幾秒鐘,且會返回個0x00h,不知原因
10.(最不可能的地方,也許就是那個結果)