[geeks] serial LCD weirdness..
Shannon Hendrix
shannon at widomaker.com
Tue Aug 19 21:23:10 CDT 2008
I've been writing a daemon to control a simple LCD (EZIO-100 aka
MTB134).
It's a 3-wire serial LCD.
I wrote the serial and lcd modules and it was working fine, displaying
a series of messages, looked great.
Then I added the code to poll the keys on a timer, and that tested OK.
However, they do not work together.
I added everything to the main event loop for the daemon and now data
being written to the LCD occasionally is corrupted.
All of the write() commands return success, so there is no error that
I can detect in the code.
Comment out the key polling, and it is fine again.
The LCD is a very simple 3-wire serial unit running at 2400bps. To
send data, you just send it and it displays it.
To send a command you prefix your write with 0xFE and then the command.
To read keys after sending the read key command, you issue a read and
just check the first two bytes: if buf[0] = 0xFD, then buf[1] is a bit-
mask of the keys pressed.
Very simple.
Very not working.
Can anyone think of why sending the read key command to a serial LCD
would cause write to occasionally be corrupted?
I thought maybe it was my termios structure, but I've used much the
same setup for many years without issue on other LCDs:
/* input modes */
term.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | INPCK| ISTRIP
| INLCR | IGNCR | ICRNL | IXON | IXANY
| IXOFF );
term.c_iflag |= IGNPAR;
/* output modes */
term.c_oflag &= ~( OPOST | ONLCR | OCRNL | ONOCR | ONLRET );
/* control modes */
term.c_cflag &= ~(CSIZE|PARENB|CRTSCTS|PARODD|HUPCL);
term.c_cflag |= CREAD|CS8|CSTOPB|CLOCAL;
/* local modes */
term.c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|FLUSHO|PENDIN);
term.c_lflag |= NOFLSH;
I suppose the LCD could be defective, or maybe it just plain sucks...
but if anyone has any ideas I would greatly appreciate it.
--
"Where some they sell their dreams for small desires."
More information about the geeks
mailing list