From: Julien J. <soj...@fr...> - 2005-08-25 22:04:17
|
Hello to all of you Gumstix users, I know the problems with /dev/ttyS2 have been discussed many times here, but after a week of hard work, I still can't get it to work correctly and I hope someone can help me. I'm trying to hook up an ATMEGA8L to the Gumstix through a serial line. The ATMEGA8L USART is set up to 8bit, no parity, 1 stop bit. Tested with a terminal program, the ATMEGA sends exactly what it has to send, meaning a single byte which gives the status of 8 switches hooked to the ATMEGA (1 bit per switch). The ATMEGA is hooked up to the Gumstic through a Breakout-TH. Now on the Gumstix side. I set up /dev/ttyS2 like this: # modprobe proc_gpio # echo "AF2 in" > /proc/gpio/GPIO46 # echo "AF1 out" > /proc/gpio/GPIO47 # stty -F /dev/ttyS2 raw ispeed 9600 ospeed 9600 (note: stty -F /dev/ttyS2 -ixon speed 9600 never worked for me) Than I run a little program I built: #include <stdio.h> int main(void) { int s; unsigned char byte; if((s=open("/dev/ttyS2", "O_RDONLY") == 0) { printf("Can't open /dev/ttyS2\n"); exit(1); } while(1) { read(s, &byte, 1); printf("byte: %d\n", byte); } close(s); // never reached return(0); } And I get rubish half of the time! Really half of the time. It looks like the 4 most significant bits are shifted left during transfer, while the 4 least significant bits are left untouched. For example, 0b1111_1011 would be transfered right but 0b1011_1111 would arrive as 0b0111_1111. This is really strange. I played with the stty options for days, but to no avail. I programmed another ATMEGA to send text trough the serial line so I could use cat /dev/ttyS2. I observed the same strange shifting phenomenon plus the OxFF byte would be added after each char sent. Has anyone any idea to solve this? Has anyone successfully hooked up an ATMEGA (or any other Atmel AVR) to a Gumstix (except with Robostix)? Thanks in advance, Julien |