Hi Everyone, I've got a 16f628 monitoring a pot and some switches, hooked up to a max232 and then into my linux box's com port. I'm using the '628's hardware USART. The linux eqivalent of HyperTerm (minicom) is printing out exactly what I'm sending from the '628, but for the life of me I can't get my own C program to do it too. All I get from the port is garbage. There's loads of linux serial port programming docs out there, but none I've seen have a nice basic example in C of initialising it and reading from it. Does anyone have a link to a C example of receiving data from a PIC? Or maybe some kind soul that's done this before can see an obvious mistake that I'm making? :) I'll paste in some code below, Cheers, Tim /* Some variables */ struct termios COM_options; // Com port settings int fd; // Com port descriptor char buffer[255]; // Input buffer char *bufptr; // Current char in buffer int nbytes; // Number of bytes read /* Open the port */ /* I'm using a USB->serial converter.. */ fd = open("/dev/ttyUSB0", O_RDONLY | O_NOCTTY | O_NDELAY); /* Get the current port options */ tcgetattr(fd, &COM_options); /* 8 bits, no parity (8N1) */ COM_options.c_cflag &= ~PARENB; COM_options.c_cflag &= ~CSTOPB; COM_options.c_cflag &= ~CSIZE; COM_options.c_cflag |= CS8; /* Set the baud rates to 9600 */ cfsetispeed(&COM_options, B9600); cfsetospeed(&COM_options, B9600); /* Enable the receiver and set local mode */ COM_options.c_cflag |= (CLOCAL | CREAD); /* set raw input, 1 second timeout */ COM_options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); COM_options.c_oflag &= ~OPOST; COM_options.c_cc[VMIN] = 0; COM_options.c_cc[VTIME] = 10; /* set the options */ tcsetattr(fd, TCSANOW, &COM_options); /* read characters into our string buffer until we get a CR or NL */ bufptr = buffer; while ((nbytes = read(fd, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) { bufptr += nbytes; if (bufptr[-1] == '\n' || bufptr[-1] == '\r') break; } /* nul terminate the string */ *bufptr = '\0'; /* Print out received data */ printf("Data: %c\n", buffer); /* Close the com port */ close(fd); -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body