Hi , everybody
I use olimex-LPC2468 board to test UART#1 to send data. I use the same code and only modify [ #define DEV “/dev/ttyS1” ] this line .
The UART#0 can send data and show in the terminal, but the UART#1 can’t.
I use the command [ echo “kkk” > /dev/ttyS1 ] to test UART#1,but it still doesn’t echo.
Who can help me and give me some suggestions ?
Best Regards.
Thanks.
The code as follows :
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BAUDRATE B115200
#define DEV “/dev/ttyS1”
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
main() {
int fd,c, res;
struct termios oldtio,newtio;
char buf[255];
fd = init_dev(&oldtio);
while (STOP==FALSE) {
send_cmd(fd,“hello”);putchar(0x0d);
usleep(500000);
}
tcsetattr(fd,TCSANOW,&oldtio);
}
/* write the users command out the serial port */
int send_cmd(int ftty,char * str)
{
int result;
result = write(ftty,str,strlen(str));/argv[4], strlen(argv[4]));/
if (result < 0)
{
printf(“Write command:%s to serial failed\n”,str);
close(ftty);
exit(1);
}
}
int init_dev(struct termios *oldtio)
{
int fd,status;
unsigned char cmd[17];
struct termios newtio;
//open carmo device
fd = open(DEV, O_RDWR| O_NOCTTY|O_NDELAY);
if (fd ==-1)
{
perror("open"DEV);
return -1;
}
else //set to block;
fcntl(fd, F_SETFL,0);
printf(“open serial ok\n”);
tcgetattr(fd,oldtio); //save current serial port settings
bzero(&newtio, sizeof(newtio)); // clear struct for new port settings
//configure the serial port;
cfsetispeed(&newtio,B115200);
cfsetospeed(&newtio,B115200);
newtio.c_cflag |=CLOCAL|CREAD;
/8N1/
newtio.c_cflag &= ~CSIZE; /* Mask the character size bits */
newtio.c_cflag |= CS8; /* Select 8 data bits */
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CRTSCTS;//disable hardware flow control;
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);/raw input/
newtio.c_oflag &= ~OPOST; /raw output/
tcflush(fd,TCIFLUSH);//clear input buffer
newtio.c_cc[VTIME] = 100; /* inter-character timer unused */
newtio.c_cc[VMIN] = 0; /* blocking read until 0 character arrives */
tcsetattr(fd,TCSANOW,&newtio);
return fd;
}