Serial ports again

I didn’t check the registers yet - I run into another strange thing.

the function tcischars(serialport)
returns me info that there are n characters on the port

so I use the function read(serialport,buf,nbytes)
and function read() returns me -1, the buffer (buf) is empty and
the tcischars returns 0

what is happening??? :open_mouth:

When you say read() returns -1 you need to provide the errno.

Previously it was errno 11, is that the case with this error?

Are you absolutely sure that no other process also has the port open?

What is the output of stty < /dev/serialport when this is happening?

erro is 2211 still

stty </dev/ser2

Name: /dev/ser2
Type: serial
Opens: 1
+edit
+isflow +osflow +ihflow +ohflow
intr=^C quit=^\ erase=^? kill=^U eof=^D start=^Q stop=^S susp=^Z
lnext=^V min=01 time=00 pr1=^[ pr2=5B left=44 right=43 up=41
down=42 ins=40 del=50 home=48 end=59
par=none bits=8 stopb=1 baud=115200 rows=0,0

my app has the port open and writes to it from time to time but with reading I got problems

You don’t really say what type of problems you are having. At that speed, 115200baud, the port might be a little more sensitive to noise than you expect. Could that be the problem? Also, make sure you are using a full 9 wire serial connection and that if there is a modem eliminator on cable or connector that it is not simple three wire version. Otherwise you will lose any hardware protocol. At 115200 baud that would probably be disastrous.

I changed the bound rate to 9600 but its still the same.

The next strange thing is that if I do

cat < /dev/ser2

and send random characters via hyper terminal and press enter - they appear but if I use a different application (the listen32 ) and send some data they won’t be there.
( However If just after that I return to hyper terminal and send anything else the message from the listen 32 appear ).

I think that I don’t really understand what is going on.

but that still don’t brings me closer to understanding why function read() returns -1 and don’t put anything to the buffer. :frowning:

Try something simple like this:

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

int main(int argc, char *argv[]) {
char byte;
int fd = open( “/dev/ser1”, O_RDWR);
while(1){
if( read(fd,&byte,1) == -1)
fprintf( stderr, “Read error %d\n”, errno ) ;
else
fprintf( stderr, “Read [%c]\n”, byte ) ;
}
}

Sorry to reply today but I have access to the board Mon-Fr ;]

I used your code and some of your ideas and manage to get one port up and running perfectly (almost) the other two seems to be resistive to my motivation and persuasion :smiley:

But I run into another strange problem - Now I send messages /receive them but after a while my port is starting to go nuts.

It stills get the messages but when I try to send something I get err 11 resource temporary unavailable - even if I try to open() it again the same thing happens - furthermore until I reset the board no application can send() to it :open_mouth:

when I do echo “smt” > /dev/ser2 it does nothing (hangs kind off)

:frowning:

My advice would be to use a hardware debugger to see if you can send and receive a byte at a time without any trouble. If not, it’s a hardware issue (broken hardware or it’s not being configured correctly at boot time - clocks, gpios, port enable, power management, etc). If you can then it’s time to dive into the driver source to see where things are going wrong. If you don’t have experience with the way serial ports work you’ll have a bit of a learning curve.