Hi, I am using the serial port 0 of the mini2440 (ttySAC0) and I can transmit/receive data. Now I would like to interface in RS-485 and therefore I need to take control over the RTS or CTS UART pins. I see that those two pins are mapped on the DB9 connector of the mini2440. Has anyone succeeded to manually control the state of one of those pins ? I tried using IOCTL: void setrts(int fd, int on) { int controlbits; ioctl(fd, TIOCMGET, &controlbits); if (on) { controlbits |= TIOCM_RTS; } else { controlbits &= ~TIOCM_RTS; } ioctl(fd, TIOCMSET, &controlbits); } } I also tried the TIOCMBIS or TIOCMBIC command of IOCTL. When I execute the code, the ioctl function returns without error but he RTS line stays at the same level, without toggling. I am quite new to LINUX and I don't know where to look in the drivers to determine if they support this particular ioctl command. Anyone has an idea ? Thanks.
Serial port RTS and CTS toggling
I have the same problem too with MINI2440. Data is transmitted and received via ttySAC0, but: I used methods mentioned above and didn't get any result. RTS line stays at the same level, without toggling. And I also need RTS line to control RS-485 transceiver.
If you can solve this and get control of the RTS line, consider using an automatic RS485 driver (I assume you are using one anyway because the COM0 port is RS232 levels) as these will control the transmit/receive from the state of the transmit line. I have used these a number of times when it is not possible to toggle the TX/RX on them in the normal way with RTS. Good luck Dave...
#include <termios.h> #include <stdio.h> #include <fcntl.h> #include <sys/ioctl.h> #include <unistd.h> #include <stdlib.h> #include <asm/ioctls.h> #define FALSE 0 #define TRUE 1 #define MODEMDEVICE "/dev/ttySAC0" int fd; int output_tx(int val) { int retorno,argumento; if(val) { retorno=ioctl(fd,TIOCSBRK,&argumento); } else { retorno=ioctl(fd,TIOCCBRK,&argumento); } return retorno; } int output_rts(int val) { int retorno,argumento=TIOCM_RTS; if(val) { retorno=ioctl(fd,TIOCMBIS,&argumento); } else { retorno=ioctl(fd,TIOCMBIC,&argumento); } return retorno; } int output_dtr(int val) { int retorno,argumento=TIOCM_DTR; if(val) { retorno=ioctl(fd,TIOCMBIS,&argumento); } else { retorno=ioctl(fd,TIOCMBIC,&argumento); } return retorno; } int main() { fd = open (MODEMDEVICE, O_RDWR|O_NOCTTY|O_NONBLOCK); if (fd <0) {perror(MODEMDEVICE); exit(-1); } output_dtr(0) ; output_tx(0); output_rts(0); while(TRUE) { printf("cambia \n"); output_dtr(1) ; usleep(1);//1seg output_dtr(0) ; usleep(1);//1seg output_tx(1); usleep(1);//1seg output_tx(0); usleep(1);//1seg output_rts(1); usleep(1);//1seg output_rts(0); usleep(1);//1seg } close(fd); return 0; }
I compiled the kernel with sysfs and use one of the GPIO lines for RS-485 direction, and it is plenty fast at switching.