Marcos Placona Blog

Programming, technology and the taming of the web.

Getting serial ports to work on Linux

Reading time: 4 – 6 minutes

Migration in actionPhoto by: lilit

I’ve recently been “forced” to move my desktop from Windows to Linux again. Basically my current desktop “decided” it won’t support Windows anymore, and any attempt to start it ends up in a BSOD, and I just got fed-up of trying to get it to work.

In fact, all of my development at home is done on Linux anyway, and I was just using windows as my dummy operating system, and using virtualization with my development environment. move to Linux works just as well.

As usual the move to Ubuntu 10.4 was a breeze, and I didn’t even have to download any of the drivers for things like graphics card, wireless or external hard-drives. everything worked straight away.

However, after I started to play with my “new” box, I noticed that my external serial ports were not working properly. They were passing the right signal and voltage, but somehow not being able to receive any feedback.

I use serial ports for RS-232 protocol a lot with my pic programming, and although I could simply use a Serial-to-USB cable, I find that it’s just an extra layer, and you could easily blow your USB module should you do anything wrong.

PCI card to two serial portsThe device I’m using is a PCI card that gives me two serial ports. I got it off eBay for a couple of pounds, and so far it has been working flawlessly.

Its communication is a lot faster than via USB, as I’m connected directly to the motherboard, therefore, no “middle-man” is used during the process.

As described previously, it started to malfunction after I moved on to Ubuntu, and even after I installed the correct driver that accompanies it, I would still not be able to download anything to my pic. the error I was getting was:

Verification error – 0x00 transmitted but 0xFFFFFF80 received at byte 1

After some research, I found out that  the driver that comes with the board, does little or nothing to make sure it works properly on Linux, and I would  have to make sure the board was properly “initiated” once the operating system loaded up.

A quick Google brought me to this. This guy gives a whole explanation of all the inner-workings and reasons why thigs aren’t working, and he happens to also be using the same board as I am.

He also mentions that you can list all the available COM ports on your system by issuing the following command on terminal:

setserial -g /dev/ttyS*

This was returning:

/dev/ttyS0, UART: undefined, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: undefined, Port: 0x1108, IRQ: 18
/dev/ttyS2, UART: undefined, Port: 0x1100, IRQ: 18
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

The software I use to program my pic micro-controller was able to detect it, on /dev/ttyS0, so that’s what I needed to get working for now.

on the website mentioned above, the guy mentions he was able to get everything working by issuing the following command:

sudo setserial /dev/ttyS[YOUR-PORT_HERE] uart 16550A

I then issued it for each of my ports, and got everything to work fine.

sudo setserial /dev/ttyS0 uart 16550A
sudo setserial /dev/ttyS1 uart 16550A

Now, when I run setserial -g /dev/ttyS*, I get:

/dev/ttyS0, UART: 16550A, Port: 0xe800, IRQ: 22
/dev/ttyS1, UART: 16550A, Port: 0xe400, IRQ: 22
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

Next step was add this to my /etc/rc.local so it runs on startup, and everything is fine again.

I know this is slightly off-topic, but I thought it might be of help to somebody in the future.

16 Comments

  1. If you start using Linux, normally you don’t want to switch back to Windows. It used to be a Problem, that there have been missing Software on Linux, but now after all this years there is a Solution or Software for every desire on Linux. This plattform improoved so much, that you can use it now for almost everything. So I will never go back to Windows. Long live Linux! :-)

  2. Just installed a card similar to yours, checked with

    # setserial -g /dev/ttyS[0123]
    /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
    /dev/ttyS1, UART: undefined, Port: 0x1040, IRQ: 169

    didn’t look good, googled and found your fix
    Problem to solution in 2 minutes, thanks

  3. Marcos Placona

    March 26, 2011 at 22:46

    Very glad my blog post helped you Stephen.

  4. Thanks a lot, I’ve been weeks trying to make my Boarduino work untill I found this!

  5. Marcos Placona

    May 13, 2011 at 11:31

    That’s very good news. Glad it worked out for you.

    Cheers

  6. Hi can you please give me the command to add it in to startup
    its my first week with Ubuntu
    thank you

  7. Please let me know how to get it rc.local.
    What do I have to fill in.
    Just as Sam new in this.

    Thanks in advance

  8. Hi, try to do that but got this:
    setserial /dev/ttyS0 uart 16550A
    ->Cannot set serial info: Device or resource busy ???

    any help please, thanks!

  9. hhey,,you are the mannnnnnnnnnnnnn bro,,
    solved my problemmmmmmm..

    thnx a tonnn!!

  10. Thanks for this, I’ve been trying to resolve this problem for weeks, now my 4 port serial card works a treat.

  11. Marcos Placona

    February 6, 2013 at 18:16

    Glad to have helped ;-)

  12. Hello Marcos, all. After been thru several web pages, here I found the closest answer to my issue, and I think I am about to solve it, but not yet…
    Here is what I have:
    BEFORE:
    $ setserial -g /dev/ttyS*
    /dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
    /dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
    /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
    /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

    Change at /etc/rc.local:
    sudo chmod 777 /dev/ttyS0
    sudo chmod 777 /dev/ttyS1
    sudo chmod 777 /dev/ttyS2
    sudo chmod 777 /dev/ttyS3
    sudo setserial /dev/ttyS0 uart 16550A
    sudo setserial /dev/ttyS1 uart 16550A
    sudo setserial /dev/ttyS2 uart 16550A
    sudo setserial /dev/ttyS3 uart 16550A
    exit 0

    After:
    $ setserial -g /dev/ttyS*
    /dev/ttyS0: No such device
    /dev/ttyS1: No such device
    /dev/ttyS2: No such device
    /dev/ttyS3: No such device

    I have two Serial PCI cards as the one above.
    $ lspci -vv -d 5372:6872
    04:00.0 Communication controller: Device 5372:6872 (rev 01)
    Subsystem: LSI Logic / Symbios Logic Device 0012
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=slow >TAbort- <TAbort- SERR- TAbort- <TAbort- SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 9
    Region 0: I/O ports at 1080 [size=8]
    Region 1: I/O ports at 1078 [size=8]
    Region 2: I/O ports at 1070 [size=8]
    Region 3: I/O ports at 1068 [size=8]
    Region 4: I/O ports at 1060 [size=8]
    Region 5: I/O ports at 1040 [size=16]

    Any ideas will be greatly appreciated.

  13. Here is the complete lspci output:

    04:00.0 Communication controller: Device 5372:6872 (rev 01)
    Subsystem: LSI Logic / Symbios Logic Device 0012
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=slow >TAbort- <TAbort- SERR- TAbort- <TAbort- SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 9
    Region 0: I/O ports at 1080 [size=8]
    Region 1: I/O ports at 1078 [size=8]
    Region 2: I/O ports at 1070 [size=8]
    Region 3: I/O ports at 1068 [size=8]
    Region 4: I/O ports at 1060 [size=8]
    Region 5: I/O ports at 1040 [size=16]

  14. Lucas,
    Did you ever manage to fix the problem of after trying to manually set the UART having all devices not recognized?

    I have a similar problem in which I’m trying to communicate through the DB-9 serial out on my PC. Originally when running

    $ setserial -g /dev/ttyS*
    /dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
    /dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
    /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
    /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

    At which point I try to define the UART by running:
    $ sudo setserial /dev/ttyS0 uart 16550A
    $ sudo setserial /dev/ttyS1 uart 16550A
    $ sudo setserial /dev/ttyS2 uart 16550A
    $ sudo setserial /dev/ttyS3 uart 16550A

    Which leads to
    $ setserial -g /dev/ttyS*
    /dev/ttyS0: No such device
    /dev/ttyS1: No such device
    /dev/ttyS2: No such device
    /dev/ttyS3: No such device

    Have you managed to solve this, or has it eluded you too

  15. IBM netvista, model 635011U

    Same issue. Want to use the DB9 serial port. (Putty)

    setseral -g /dev/ttyS*
    /dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
    /dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
    /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
    /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

    if we set the uart to 16650A the devices dissapear.
    $ sudo setserial /dev/ttyS0 uart 16550A

    $ setserial -g /dev/ttyS*
    /dev/ttyS0: No such device
    /dev/ttyS1: No such device
    /dev/ttyS2: No such device
    /dev/ttyS3: No such device

    I have used the Boot configuration of BIOS to turn ON the legacy ports.

    Does anybody remember how to configure the serial ports?

  16. Hi,
    I have tried as you mentioned, after that serial port started receiving the data but unable to transmit the data from the port. I windows these serial port is working proper. what might be the issue. Please help to resolve.

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>