Next Previous Contents

9. Can I Use More Than Two Serial Devices?

You don't need to read this section, unless you want to use three or more serial devices... (assuming you don't have a multiport board).

Providing you have another spare serial port, yes you can. The number of serial ports you can use is limited by the number of interrupts (IRQs) and port I/O addresses we have to use. This is not a Linux limitation, but a limitation of the PC bus. Each serial devices must be assigned it's address and should be assigned it's own interrupt. If two devices share the same interrupt, it may work OK provided the two devices are not operating at the same time. (In most cases, the two programs must not even be running at the same time.) A serial device can be a serial port, an internal modem, or a multiport serial board.

Multiport serial boards are specially designed to have multiple serial ports that share the same IRQ for all serial ports on the board. Linux gets data from them by using a different I/O address for each port on the board.

9.1 Choosing Serial Device Interrupts

Your PC will normally come with ttyS0 and ttyS2 at IRQ 4, and ttyS1 and ttyS3 at IRQ 3. You can see what IRQs are in use by typing: setserial /dev/ttyS2, etc. Looking at /proc/interrupts will show some of them. To use more than two serial devices, you will have to reassign an interrupt. A good choice is to reassign an interrupt from your parallel port. Your PC normally comes with IRQ 5 and IRQ 7 set up as interrupts for your parallel ports, but few people use two parallel ports. You can reassign one of the interrupts to a serial device, and still happily use a parallel port. You will need the setserial program to do this. In addition, you have to play with the jumpers on your boards, check the docs for your board. Set the jumpers to the IRQ you want for each port.

You should set things up so that there is one, and only one interrupt for each serial device. Here is how Greg set his up in /etc/rc.d/rc.local - you should do it in a file which runs upon startup:

/sbin/setserial /dev/ttyS0 irq 3        # my serial mouse
/sbin/setserial /dev/ttyS1 irq 4        # my Wyse dumb terminal
/sbin/setserial /dev/ttyS2 irq 5        # my Zoom modem 
/sbin/setserial /dev/ttyS3 irq 9        # my USR modem

Standard IRQ assignments:

              IRQ  0    Timer channel 0
      IRQ  1    Keyboard
              IRQ  2    Cascade for controller 2
              IRQ  3    Serial port 2
              IRQ  4    Serial port 1
              IRQ  5    Parallel port 2
              IRQ  6    Floppy diskette
              IRQ  7    Parallel port 1
              IRQ  8    Real-time clock
              IRQ  9    Redirected to IRQ2
              IRQ 10    not assigned 
              IRQ 11    not assigned
              IRQ 12    not assigned
              IRQ 13    Math coprocessor
              IRQ 14    Hard disk controller 1
              IRQ 15    Hard disk controller 2

There is really no Right Thing to do when choosing interrupts. Just make sure it isn't being used by the motherboard, or any other boards. 2, 3, 4, 5, or 7 is a good choice. ``not assigned'' means that currently nothing standard uses these IRQs. Also note that IRQ 2 is the same as IRQ 9. You can call it either 2 or 9, the serial driver is very understanding. If you have a serial board with a 16-bit bus connector , you can also use IRQ 10, 11, 12 or 15.

Just make sure you don't use IRQ 0, 1, 6, 8, 13 or 14! These are used by your mother board. You will make her very unhappy by taking her IRQs. When you are done, double-check /proc/interrupts and make sure there are no conflicts.

9.2 Setting Serial Device Addresses

Next, you must set the port address. Check the manual on your board for the jumper settings. Like interrupts, there can only be one serial device at each address. Your ports will usually come configured as follows:

ttyS0 address 0x3f8
ttyS1 address 0x2f8
ttyS2 address 0x3e8
ttyS3 address 0x2e8

Choose which address you want each serial device to have and set the jumpers accordingly. I have my modem on ttyS3, my mouse on ttyS0, and my terminal on ttyS2.

When you reboot, Linux should see your serial ports at the address you set them. The IRQ Linux sees may not correspond to the IRQ you set with the jumpers. Don't worry about this. Linux does not do any IRQ detection when it boots, because IRQ detection is dicey and can be fooled. Use setserial to tell Linux what IRQ the port is using. You can check /proc/ioports to see what I/O port addresses are in use after Linux boots.


Next Previous Contents