OpenBSD 4.3 installed smoothly, but Ive been wrestling with serial
communication over COM2 for days now. At the moment I have a simple C program
designed to echo any data sent to the serial port to stdout. Ive tested the
program on other OpenBSD 4.3 PCs without issue, but when I move the code to
the Soekris board, I see data being received, but its entirely corrupted. At
this point I have tried sending the data at multiple baud rates, both with and
without CTS/RTS. The results are always the same. I receive data as its
being sent, but its not the data I expect.
The code for the echo program is listed below. Must CTS/RTS be connected? I
noticed in another message thread, 19200 is the recommended baud rate for
COM2. Is this true? If so, why? Must I use 19200? Any other
recommendations?
Strangely enough, I actually always receive data back from the COM2 connection
as well, whether the echo program is running or not. For example, sending the
character t, I get back 0x0000. If I send test, I receive
0x000246000000. Again, this occurs whether or not the program is running
(note that the program doesnt actually return anything via the serial port at
all). I suspect this is a configuration issue, but quite honestly Im a
loss. Any suggestions would be greatly welcomed.
Have a great weekend - Greg
Echo Program:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/cua01"
#define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define
TRUE 1
int main(int argc, char **argv)
{
unsigned char serialbuf[512];
int fd, resume;
struct termios oldtio, newtio;
int n = 0;
// Open serial port for communications
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd < 0)
{
perror(MODEMDEVICE);
exit(-1);
}
else
{
printf("\nSerial Port Initializing...\n\n");
}
// Save existing port settings
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
/*
CRTSCTS : flow control
CS8 : 8N1
CLOCAL : local connection, no modem contol
CREAD : enable receiving characters
*/
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | CRTSCTS;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
// Activate settings
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
// Begin Receiving serial data communication
printf("\nReceiving on Serial Port...\n");
while(1)
{
resume = read(fd,serialbuf,512);
if (resume > 0)
{
printf("Size: %d\n", resume);
for (n=0; n<resume; n++)
printf("%c\n",serialbuf[n]);
}
}
tcsetattr(fd, TCSANOW, &oldtio);
return 0;
}
_______________________________________________
Soekris-tech mailing list
[email protected]
http://lists.soekris.com/mailman/listinfo/soekris-tech