|
hello,
I have a very strange problem, I'm using sam9263 with serial driver, I can receive perfectly but the driver doesn't trasmit...is there any problem regarding the start of trasmission? below the code used for test: any idea on what is happening or missing... thanks
#define NUMBER 10 int main() { int fd; /* File descriptor for the port */ struct termios options; char data_send[NUMBER]; char data_receive[NUMBER]; char ch; unsigned int SendCount; unsigned int ReceivedCount = 0; int i; fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) { perror("open_port: Unable to open /dev/ttyS0 - "); } else fcntl(fd, F_SETFL, 0);
/* * Get the current options for the port... */
tcgetattr(fd, &options);
/* * Set the baud rates to 19200... */
cfsetispeed(&options, B19200); cfsetospeed(&options, B19200);
/* * Enable the receiver and set local mode... */
options.c_cflag |= (HUPCL | CLOCAL | CREAD); options.c_cflag &= ~CSIZE; /* Mask the character size bits */ options.c_cflag |= CS8; /* Select 8 data bits */ options.c_cflag &= ~PARENB; /* Parity mode : no parity */ options.c_cflag &= ~CSTOPB;
// options.c_cflag |= CNEW_RTSCTS; /* Also called CNEW_RTSCTS/CRTSCTS, Enable hardware flow control */ options.c_cflag &= ~CRTSCTS;
// options.c_lflag |= (ICANON | ECHO | ECHOE); /* canonical input */ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* raw input */
// options.c_iflag |= (INPCK | ISTRIP); /* set input parity option */
// options.c_iflag |= (IXON | IXOFF | IXANY); /* enable software flow control */ options.c_iflag &= ~(IXON | IXOFF | IXANY);
// options.c_oflag |= OPOST; options.c_oflag &= ~OPOST;
options.c_cc[VMIN] = 0; /* minimum number to read */ options.c_cc[VTIME] = 10; /* Time to wait */
/* * Set the new options for the port... */
tcsetattr(fd, TCSANOW, &options);
for(i=0;i<10000;i++) { ch = 'h'; printf("sending, fd = %d, char = %c\n",fd,ch); SendCount = write(fd, &ch,1); if(SendCount < 1) return 1; }
i = 0; ReceivedCount = 0; while(1) {
printf("receiving, fd = %d\n",fd); // i = read(fd, data_receive + ReceivedCount, NUMBER - ReceivedCount); i = read(fd, &ch, (int) 1);
if (i != 0) { data_receive[ReceivedCount+i] = ch; ReceivedCount += i; printf("%c\n", ch); }
if(ReceivedCount == NUMBER) break; }
close(fd); return 0; }
|