# Trouble with serial port

## rawbeefman

So I notice there are a few RS232 experts on the forums, so I figured I would reach out for assistance.  In November of 2011 (Kernel 2.6.34, I believe); I had a project that interacted with different 'things' around my house, via a serial cable.  A new job, a new girl, and other say, 'crisis' occured in my life and I put the project on hold.  I decided to revisit the project today.  I booted the server up and everything worked great ... until I opted to update my system.  udev required a kernel re-compile, I jumped to 3.6.11 and then everything serial-related stopped working.  Damn.

So, it looks like the serial port is recognized and appropriate modules are loaded:

```
tux-server ~ # dmesg | grep tty

[    0.000000] console [tty0] enabled

[    0.546195] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

[    0.811200] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A

[    0.832977] 00:08: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A

[    0.854135] 00:09: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

 # stty -a -F /dev/ttyS0

speed 1200 baud; rows 0; columns 0; line = 0;

intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O;

min = 1; time = 13;

-parenb -parodd cs8 hupcl -cstopb cread clocal crtscts

-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8

opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0

-isig -icanon iexten -echo -echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

```

In 2011, all my code referenced /dev/ttyS0, but I noticed there are pinouts on the board itself for another serial port.  I assume the hardware references wouldn't swap.

So here is where I stand.  I removed the serial cable and shorted pins 2 and 3.  I ran a 

```
# cat < /dev/ttyS0
```

on terminal window 1 and a 

```
# echo 'test' >> /dev/ttyS0
```

in window 2.  Nothing.  Why?  Blah, frustrating.

This might be of interest as well.  I remember when I set everything up way back when, I used minicom to send and receive bytes.  So i emerged it and set it up.  But then when I started it up, it would hang.  I can't Ctrl+A+Z and I can't Ctrl+C and if I echo anything to ttys0 it won't show up.  Weird, right?  I am sure the resident expert can explain this to me -- I would venture to guess minicom predates me and I was just starting to feel old.

After a few failures with minicom, I ran a cat on /dev/ttyS0 and executed my code which opens a connection, configures it (from the awesome posix serial programming guide) and then sends a few bytes out.  Nothing.  Again, this worked fine for a few years and even this morning, until I ran a new kernel.

I hope I was thorough and I hope someone can be of assistance.  Thanks!

----------

## NeddySeagoon

rawbeefman,

Confirm that /dev/ttyS0 and friends exist and are not symlinks. Check their permissions too.

If in doubt, post the output of

```
ls -l /dev/ttyS*
```

Put your kernel .config on a pastebin too please

----------

## rawbeefman

Thanks Ned.

```
 #  ls -l /dev/ttyS*

crw-rw---- 1 root uucp 4, 64 Feb  3 19:14 /dev/ttyS0

crw-rw---- 1 root uucp 4, 65 Feb  3 17:59 /dev/ttyS1

crw-rw---- 1 root uucp 4, 66 Feb  3 17:59 /dev/ttyS2

crw-rw---- 1 root uucp 4, 67 Feb  3 17:59 /dev/ttyS3
```

Here is my kernel configuration:

http://pastebin.com/4uMPX0pv

----------

## rawbeefman

Ned, I discovered something. Perhaps it is progress.

I still had my code running as a cron job every minute.  I disabled these jobs -- now minicom opens just fine and I can perform the configurations.

Okay; so I run # cat < /dev/ttyS0 on one terminal and minicom on the other.  I can type one letter in minicom before it freezes and I have to close the session.

Perhaps I just have a bit more configuring to do?  One last things, I ran this:

```
stty -F /dev/ttyS0 -echo -onlcr
```

Thanks.

----------

## NeddySeagoon

rawbeefman,

If you can type one letter then it freezes, I suspect you have hardware handshaking in.

That would mean it would send a character assert the handshake and wait for a reply that isn't going to come, as you only have pins 2 and 3 linked together. 

If you  don't see the character, or its jibberish, suspect the baud rate, stop bits and/or parity.

A popular setup is 9600 baud, 8n1.  Thats as fast an as unbuffered serial port will run on a PC without dropping characters, sending 8 data bits, no parity and 1 stop bit.

You should be able to make minicom talk to itself by shorting pins 2 and 3, turning off both hardware and software handshaking.

If you leave local echo on. you will get two copies of everything you type. The local echo copy and the copy that goes through the pin 2 to 3 link. 

Once you can talk to yourself, you can try talking to other equipment.

----------

## rawbeefman

Thanks Neddy; that is incredibly helpful.  Can you tell me if handshaking is set at the hardware level (change a setting with stty) or at the software level (change a setting in minicom / update configuration in code)?

----------

## NeddySeagoon

rawbeefman,

Mincom can set hardware handshaking and software handshaking. 

Hardware handshaking is implemented in the UART but I think software handshaking is in the driver.

Note that you cannot use software handshaking with a binary data stream, as the handshake symbols are valid binary character values too.

----------

## billium

Look up picocom it is easy to use.

I've Not had any problems with ttys on 3.7.4

Is your user in the uucp group? .. whoops just noticed you are using root sorry.

----------

