Dear Support Team,
has anyone succesfully used an UART as RS485 port? I tried with UART B (/dev/ttymxc1) and a SN65HVD10 driver circuit. I'm able to send data but I'm not able to receive data. RS485 support in general is included in kernel /drivers/tty/serial/imx.c.
(armstonea9r2dl with software release 3.0)
CTS is wired to circuits RE/DE pins. This seems to work OK. Maybe the problem may come from levels of RX/TX lines before setting RE/DE to low for reading?
Here some pieces of code from my application:
Code
- #define TIOCSRS485 0x542F
- struct termios termAttr;
- int fdRTU;
- ...
- fdRTU = open("/dev/ttymxc1", O_RDWR | O_NOCTTY | O_NONBLOCK);
- if (fdRTU==-1) {
- printf("Unable to open RTU port\n");
- return(-1);
- }
- fcntl(fdRTU, F_SETFL, FASYNC);
- fcntl(fdRTU, F_SETOWN, getpid());
- tcgetattr(fdRTU,&termAttr);
- cfsetispeed(&termAttr,B19200);
- cfsetospeed(&termAttr,B19200);
- termAttr.c_cflag &= ~PARENB;
- termAttr.c_cflag &= ~CSTOPB;
- termAttr.c_cflag &= ~CSIZE;
- termAttr.c_cflag |= CS8;
- termAttr.c_cflag |= (CLOCAL | CREAD);
- termAttr.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN);
- termAttr.c_oflag &= ~OPOST;
- tcsetattr(fdRTU,TCSANOW,&termAttr);
- struct serial_rs485 rs485conf;
- rs485conf.flags |= SER_RS485_ENABLED;
- rs485conf.flags |= SER_RS485_RTS_ON_SEND;
- rs485conf.flags &= ~SER_RS485_RTS_AFTER_SEND;
- rs485conf.delay_rts_before_send = 0x0001;
- rs485conf.delay_rts_after_send = 0x0001;
- rs485conf.flags &= ~SER_RS485_RX_DURING_TX;
- if (ioctl (fdRTU, TIOCSRS485, &rs485conf) < 0) {
- printf("Error RS484\n");
- }
- modOutData[0]=35;
- modOutData[1]=2;
- modOutData[2]=0;
- modOutData[3]=0;
- modOutData[4]=0;
- modOutData[5]=1;
- modOutData[6]=0xBF;
- modOutData[7]=0x48;
- write(fdRTU,modOutData,8);
- size=read(fdRTU,modInData,8);
I also tried to find some newer versions of /drivers/tty/serial/imx.c but without success (at least while compiling the kernel).
Anyone any idea?
Thanks.