From: Joost M. <joo...@ho...> - 2007-06-07 14:51:35
|
Hi All, I am trying to write something to the serial port of the gumstix (the serial port is located on the tweener expansion board). First I connected the gumstix to my PC via serial. When doing this I listen on the PC side what is written to serial port on the Gumstix side. This seems to work correctly (since I am writing bytes, some characters do not appear on the screen). However, when connecting the device I want to control to the Gumstix it does not work correctly. Now is the case that for the device I want to control a specific protocol is needed. The key element in this protocol is to switch from "space" to "mark" parity and vice-versa. Please see the code below where I do the setup in the first snippet, and I do the switching of parity in the second snippet. My feeling says that something goes wrong when cross-compiling the code to the Gumstix hardware. Since the same code is working fine on my PC Linux machine (i.e. I can successfully control the device). Does anyone have experience with this? Or can anyone give me a clue were to look? Maybe someone experienced problems with "termios.h" before? Thanks a lot in advance. Kind regards, Joost Meijles PS. Reading from the serial port goes fine. ================SETUP============ int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); tcflush(fd, TCIOFLUSH); debug("serial port open"); //configure the serial port struct termios options; if(tcgetattr(fd, &options) < 0) // READ SETTINGS { debug("error getting serial port configuration"); } cfmakeraw(&options); cfsetospeed(&options, B115200); // SET SPEED cfsetispeed(&options, B115200); options.c_iflag &= ~CLOCAL; // Set ... options.c_cflag |= CLOCAL; options.c_iflag &= ~CREAD; options.c_cflag |= CREAD; options.c_iflag &= ~CSTOPB; // SET STOPBITS options.c_iflag &= ~PARENB; // SET PARITY BITS options.c_iflag &= ~PARODD; // Odd options.c_cflag |= PARENB; options.c_cflag |= PARODD; options.c_iflag &= ~CS5; // SET DATABITS options.c_iflag &= ~CS6; options.c_iflag &= ~CS7; options.c_iflag &= ~CS8; // 8 databits options.c_cflag |= CS8; options.c_cflag &= ~CRTSCTS; // SET HARDWARE FLOW CONTROL to none if(tcsetattr(fd, TCSANOW, &options) < 0) // WRITE SETTINGS { debug("error writing configuration to serial port"); } =========================================== ===============SWITCH===================== //switch the parity for writing tcgetattr(fd, &options);//get the configuration options.c_cflag &= ~PARENB; options.c_cflag &= ~PARODD; options.c_cflag |= PARENB | 010000000000; options.c_cflag &= ~PARODD; if(tcsetattr(fd, TCSAFLUSH, &options) < 0) {//set the configuration debug("error writing configuration to serial port"); } ============================================ _________________________________________________________________ Vind alles terug op je PC: Windows Live Search Toolbar http://desktop.msn.nl |