This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Problem reading data from serial Port
- From: "Ricardo Andrino" <ricardo_andrino at web dot de>
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Fri, 26 Mar 2004 10:32:13 +0100
- Subject: [ECOS] Problem reading data from serial Port
- Organization: http://freemail.web.de/
Hello again,
i am a little confused with this. My eCos application(running on th AT91EB40A) only try to read characters one by one from a host , and for this i have made a loop as follow( i have used POSIX functions):
while(1)
{
read(fd,&data,1)
printf(data)
}
The program that sends the data works fine and send always the following data sequence:
0x44 0x47 0x02 0xaa 0x03 0xa8
but my program read different sequences:
0x44 0x47 0xa8 0x44 0x02 0xaa 0xa8 or even others.
I have configured the serial port (4800, 8E1) see bellow:
fd = open(MODEMDEVICE, O_RDWR);
if (fd <0)
{
perror(MODEMDEVICE);
exit(-1);
}
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &oldtio); /* save current port settings */
/*
Set bps rate and 8n1 (8bit,parity even,1 stop-bit).
Also don't hangup automatically and ignore modem status.
Finally enable receiving characters*/
newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_cflag |= PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag &= ~PARODD;
newtio.c_cflag |= CS8;
/*
Ignore bytes with parity errors and make terminal raw and dumb.
This option can be changed*/
newtio.c_iflag = IGNPAR;
/*Don´t echo characters.Don't generate signals.No canonical
input else raw input*/
newtio.c_lflag = 0;
newtio.c_lflag &= ~(ICANON | ISIG);
newtio.c_lflag &= ~ECHO;
/* blocking read until 1 byte arrives. Warning, the option VMIN !=0 couldn't
work good in eCos */
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
/*4800 bauds in and out*/
cfsetispeed(&newtio, BAUDRATE);
cfsetospeed(&newtio, BAUDRATE);
/* now clean the modem line and activate the settings for port */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW, &newtio);
What could be the problem, timing problems, port configurations problems?
I would appreciate any kind of help.
_______________________________________________________________________
... and the winner is... WEB.DE FreeMail! - Deutschlands beste E-Mail
ist zum 39. Mal Testsieger (PC Praxis 03/04) http://f.web.de/?mc=021191
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss