This document contains instructions to help you install and configure the
National Instruments serial hardware for Linux. This document includes
information about the PCI-232/2, PCI-232/4, PCI-232/8, PCI-485/2,
PCI-485/4, PCI-485/8, PCI-232/2 Isolated, PCI-232/4 Isolated, PCI-485/2
Isolated, and PCI-485/4 Isolated interfaces.
This document assumes that you are already familiar with Linux.
Related Documentation............................... ............................................2
Test the Setup..........................................................................................11
natinst.com™, National Instruments™, and NI-Serial™ are trademarks of National Instruments Corporation. Product and company names
mentioned herein are trademarks or trade names of their respective companies.
Thanks to Vern Howie for providing suggestions and examples from his
serial suite. Also, thanks to David Lawyer, Greg Hankins, and Peter
Baumann for providing so much information in their HOWTOs.
Gather What You Need to Get Started
Before you install your PCI serial interface for Linux, make sure you have
the following:
•Linux kernel version 2.2.3 or later. The product has been thoroughly
tested with kernel version 2.2.3; howe ver , the product might work with
earlier kernel versions.
If you do not have kernel version 2.2.3 or later, or if you do not have
the following options already compiled into your kernel, you need to
recompile you kernel. Include the following options when you
configure and recompile the kernel using
Using PCI Serial with Linux2www.natinst.com
make menuconfig.
a.General Setup
–PCI Support
–PCI Quirks
–Backward-compatible
/proc/pci
b.Character Devices
–Standard/generic dumb serial support
–Extended dumb serial driver options
–Support more than four serial ports
–Support for sharing serial interrupts
•
setserial 2.14 or later. To find the version of setserial
,
enter the
following:
linux# setserial –V
•PCI Utilities 1.10 or later. You can download PCI Utilities 1.10 from
ftp://metalab.unc.edu/pub/Linux/hardware
•PCI-SERIAL.tar.gz. You can download this file from the National
Instruments FTP site at
ind_comm/serial/linux/
ftp://ftp.natinst.com/support/
After you have the file, extract and unzip it by entering the following:
linux#tar zxvf PCI-SERIAL.tar.gz
The tar command extracts and unzips PCI-SERIAL.tar.gz and
creates the sub-directory
This section is for experienced Linux users who are familiar with the
lspci and setserial tools. If you are not familiar with either of these
tools or if you require a detailed explanation of the steps, skip to the next
section, Setup.
1.If you do not have enough available serial devices (
/dev/ttyS*) for
each port on your multiport interface, create a new serial device by
entering the following:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<
port number
>
2.Find the port address, IRQ, and memory assignment of your PCI serial
interface by enter the following:
linux# lspci -v -n -d 1093:*
3.Assign the serial driver to your devices. Make sure you precede the
port addresses with
0x.
•For a PCI-232 interface, enter the following:
linux# setserial /dev/ttyS<
16550a port <
^fourport
port address
port number
> irq <
> uart
irq
>
•For a PCI-485 interface, which supports a higher baud_base of
460.8K at startup, enter the following:
linux# setserial /dev/ttyS<
16550a port <
baud_base 460800 ^fourport
port address
port number
> irq <
> uart
irq
>
4.Enable the PCI interrupt on your interface. To use intenable (from
the
PCI-SERIAL directory) to enable interrupts on your PCI serial
interface, enter the following:
linux PCI-SERIAL# ./intenable <
found in lspci
pci memory address
>
5.If you have a PCI-485 interface, set the transcei ver mode for each serial
port. Refer to the section Select Transceiver Mode for more
information about selecting a PCI-485 transceiver mode.
6.After you connect a cable between the two ports, test the setup by
running
linux#./serialtest <
serialtest (from the PCI-SERIAL directory).
port number
receive port number
>
> <
transmit
Using PCI Serial with Linux4www.natinst.com
Setup
Create Devices
After you install the serial hardware (as shown in your PCI serial getting
started manual), follow these steps to set up the interface.
Create a device for each port on your multiport interface. You only need to
do this step once. Port address is the I/O address of the device, and port number is the device/serial port number of the port. Port number is used in
the following context:
your computer are typically named from
port number you choose needs to be four or greater.
ttyS<
port number
/dev/ttyS0 to /dev/ttyS3, the
>. Since serial ports built into
Enter the
each serial port on the interface by entering the following.
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<
MAKEDEV Example
Enter the following to make the devices for a two-port interface:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS4
linux /dev# ./MAKEDEV ttyS5
Find Interface Information
Follow these instructions to find the port address, IRQ, and memory
assignment of your PCI serial interface.
Note
Repeat this section each time you add another interface or physical device to the
computer.
Note
This step may be done in normal user mode.
1.Use
with the
device codes as numbers), and the
information only on devices with a National Instruments Vendor ID
of 1093), to find the resource information of your serial interface.
linux# lspci -v -n -d 1093:*
Something similar to the following should appear. In this output, the
IRQ is 11; the memory location is 0xdff80, and the port addresses are
0xdff0 and 0xdfe0.
/dev directory , then use the MAKEDEV script to create a de vice for
port number
lspci (a command that displays information about the PCI bus)
-v option (be verbose), the -n option (show PCI vendor and
Note PCI Eight-Port Users—The PCI eight-port interfaces show only one I/O port
address listing. The addresses of the other seven I/O ports are calculated b y adding eight to
the previous port address, (n × 8 + I/O port) for 0 < n < 8. The
something similar to the following:
Assign Serial Driver
Note You need to repeat this step each time you restart your computer or until you set up
your
/etc/rc.d/rc.serial file. (Refer to the section Sample /etc/rc.d/rc.serial File for
more information on setting up the
00:0a.0 Class ff00: 1093:d140 (rev 01)
Flags: medium devsel, IRQ 11
Memory at 000dff80 (low-1M, non-prefetchable)
I/O ports at dff0
I/O ports at dfe0
Write down the IRQ, memory location, and all the I/O port addresses
for your computer.
lspci call displays
00:0a.0 Class ff00: 1093:d150 (rev 01)
Flags: medium devsel, IRQ 11
Memory at 000dff80 (low-1M, non-prefetchable)
I/O ports at df00
Assign the serial driver to your devices.
/etc/rc.d/rc.serial file.)
Enter the following to use
UART, port address, and IRQ. Use information returned from the
output, and remember to precede the port address with
linux#setserial /dev/ttyS<
port <
Note
The ^fourport flag is required regardless of how many ports you have on your
interface. The
^fourport flag tells the serial driver that you are not using an AST
setserial to tell the kernel each device’s
port address
port number
> irq <
irq
> uart 16550A
> ^fourport
lspci
0x.
four-port interface.
Caution Using an invalid port can lock up your machine.
setserial Example
Enter the following to assign the serial driver to your devices for the values
in the above two-port
linux#setserial /dev/ttyS4 uart 16550A port 0xdff0 irq
11 ^fourport
Using PCI Serial with Linux6www.natinst.com
lscpi output:
linux#setserial /dev/ttyS5 uart 16550A port 0xdfe0 irq
11 ^fourport
Assign Serial Drivers Using PCI-485
Since the PCI-485 supports a higher baud_base of 460.8K at start-up, also
enter the following at the linux prompt:
linux#setserial /dev/ttyS<
460800
port number
> baud_base
For example, enter the following to assign the serial dri ver to /dev/ttyS4
for a PCI-485 serial port at port address 0xdfe0 and IRQ 11.
linux#setserial /dev/ttyS4 uart 16550A port 0xdfe0 irq
11 ^fourport
linux#setserial /dev/ttyS4 baud_base 460800
Assign Serial Drivers Using PCI Eight-Port Interfaces
Enter the following to assign the serial driver to your devices for the PCI
eight-port
and are separated by exactly 8 bytes.
linux# setserial /dev/ttyS4 uart 16550A port 0xdf00 irq
11 ^fourport
linux# setserial /dev/ttyS5 uart 16550A port 0xdf08 irq
11 ^fourport
linux# setserial /dev/ttyS6 uart 16550A port 0xdf10 irq
11 ^fourport
linux# setserial /dev/ttyS7 uart 16550A port 0xdf18 irq
11 ^fourport
linux# setserial /dev/ttyS8 uart 16550A port 0xdf20 irq
11 ^fourport
linux# setserial /dev/ttyS9 uart 16550A port 0xdf28 irq
11 ^fourport
linux# setserial /dev/ttyS10 uart 16550A port 0xdf30 irq
11 ^fourport
linux# setserial /dev/ttyS11 uart 16550A port 0xdf38 irq
11 ^fourport
lspci output. Notice that the entries for port are consecutive
Enable PCI Interrupt
To enable the PCI interrupt on your serial interface, use intenable,
provided in the
restart your computer. If you have more than one PCI serial interface, rerun
intenable with another PCI memory address specified in the command
Use FIFOtrigger (from the PCI-SERIAL directory) to enable the receive
and transmit FIFOs and to set the trigger levels of these FIFOs.
FIFOtrigger enables the FIFO of only one serial port. T o enable the FIFO
for your other serial ports, rerun
number specified in the command line. Enter the following to use
FIFOtrigger:
linux PCI-SERIAL#./FIFOtrigger <
<
rx_trigger
Using PCI Serial with Linux8www.natinst.com
FIFOtrigger with a different serial port
port number
> <
tx_trigger
>
>
Table 1.
tx_trigger Values
Transmit FIFO Trigger Leveltx_trigger
80x00
160x10
320x20
560x30
Receive FIFO Trigger Levelrx_trigger
The hardware issues a transmit empty interrupt when the number of
characters in the transmit FIFO falls below the trigger level. Also, the
hardware issues a receive full interrupt when the number of characters in
the receive FIFO rises above the trigger level. For more information on
FIFO buffers, refer to your PCI serial getting started manual.
FIFO Example
Enter the following to set the receive FIFO trigger level to 56 and the
transmit trigger level to 32 for
linux PCI-SERIAL# ./FIFOtrigger 5 0x80 0x20
Configure struct termios
Every serial port has an associated struct termios. By using this
struct termios in a program, you can set the baud rate, character size
(number of data bits), parity, control characters, flow control, and input and
output mode. For more information about the termios structure, refer to the
termios man page. To view the termios man page, enter the
following:
linux# man termios
Table 2.
rx_trigger Values
80x00
160x40
560x80
600xC0
/dev/ttyS5:
To configure your serial port, use a program segment similar to the
If you are using a PCI-485 interface, you can select the transceiver
mode for each device and select the lower baud rates listed in
termios_program.c provided in your PCI-SERIAL directory.
Select Transceiver Mode
Use the rs485 program (from the PCI-SERIAL directory) to select the
transceiver mode.
To set the transceiver mode for other serial ports, rerun
different serial port number specified in the command line. For more
information on the transceiver control modes, refer to your serial getting
started manual. If you do not know which transceiver mode to use, choose
Four-Wire Mode.
rs485 sets the transceiver mode for only one serial port.
rs485 with a
Transceiver ModeMode
Four-Wire Mode0
Two-Wire Mode: DTR with echo1
Two-Wire Mode: DTR controlled2
Two-Wire Mode: TXRDY auto
control
Enter the following to use
linux PCI-SERIAL# ./rs485 <
rs485 Example
Enter the following to select Four-Wire Mode for /dev/ttyS5:
linux PCI-SERIAL# ./rs485 5 0
Lower Baud Rate Selection
To use a baud rate lower than 200, use setserial and the clockspeed
program (from the
single serial port from 460800 to 115200. After changing the baud base
to 115200, the max baud rate you can achieve is 115200 baud (until you
change the baud base back to 460800).
Table 3.
PCI-SERIAL directory) to lower the baud base of a
Transceiver Mode Values
rs485:
port number
> <
3
mode
>
After you change the
run the
your programs. The
Using PCI Serial with Linux10www.natinst.com
clockspeed program, you can use the lower baud rate flags in
baud_base of the serial port using setserial and
clockspeed program changes the baud base of only
Test the Setup
one serial port. To change the baud base of your other serial ports, rerun
clockspeed with a different serial port number specified in the command
line. Enter the following to set the baud base. (In this example, high equals
a baud base of 460800 and low equals a baud base of 115200):
linux# setserial /dev/ttyS<
linux PCI-SERIAL#./clockspeed <
"low"
>
port number
port number
> baud_base 115200
> <
"high" or
For example, enter the following to select a baud base of 115200 for
/dev/ttyS4 and for /dev/ttyS5:
linux# setserial /dev/ttyS4 baud_base 115200
linux# setserial /dev/ttyS5 baud_base 115200
linux PCI-SERIAL# ./clockspeed 4 low
linux PCI-SERIAL# ./clockspeed 5 low
Enter the following to change the baud base back to 460800 for
/dev/ttyS4 and for /dev/ttyS5:
linux# setserial /dev/ttyS4 baud_base 460800
linux# setserial /dev/ttyS5 baud_base 460800
linux PCI-SERIAL# ./clockspeed 4 high
linux PCI-SERIAL# ./clockspeed 5 high
After you connect the cables to the port (as shown in your PCI serial getting
started manual), run the
serialtest program (from the PCI-SERIAL
directory) to verify your setup. Make sure you specify two different ports
for the
serialtest program, as shown in the following:
linux PCI-SERIAL# ./serialtest <
<
transmit port number
receive port number
>
>
If the test is successful, it displays a SUCCESS message. If the test hangs,
press <ctrl-c> to exit the program, and continue to the next section,
Troubleshooting and Common Questions.
To test
/dev/ttyS4 and /dev/ttyS5, connect a cable between the
This section lists possible error codes and solutions.
Error Code/dev/ttyS<
SolutionThe /dev/ttyS<
port number
port number
>: no such file or directory
> does not exist in the /dev directory . Enter the
following to create the device:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<
port number
>
Error CodeCouldn't change i/o privilege level: Operation not permitted
SolutionThe program requires superuser privileges. Either exit and log in as root, or enter
the following:
linux$ su
Password: <
linux# <
enter the root password
run the program
>
>
Error Codesetserial: Cannot set serial info: Address already in use
SolutionMake sure you are entering the correct port address into setserial. Also, make
sure you are entering
linux# setserial /dev/ttyS<
0x<
port address
0x if you are specifying a hex number.
port number
> irq <
irq
> ^fourport
> uart 16550a port
Error Codeintenable: Can't open /dev/mem: Permission denied
SolutionThe program requires superuser privileges. Either exit and log in as root, or enter
the following:
linux$ su
Password: <
linux# ./intenable <
Using PCI Serial with Linux12www.natinst.com
enter the root password
PCI memory
>
>
Error Codeintenable: ERROR: Initial value of interrupt enable register
not equal to 0xC0C
SolutionMake sure that you are providing the program with the correct memory address.
Enter the following to check for the memory address:
linux# lspci -v -n -d 1093:*
00:0a.0 Class ff00: 1093:d150 (rev 01)
Flags: medium devsel, IRQ 11
Enter this address! -->Memory at 000dff80
non-prefetchable)
I/O ports at dff0
I/O ports at dfe0
I/O ports at dfa8
I/O ports at dfa0
linux# ./intenable dff80
(low-1M,
Error Coders485: ERROR: Couldn't write to /dev/ttyS<
scratch register
port number
SolutionMake sure the device was configured correctly in setserial. Enter the
What do I do if FIFOtrigger does not work immediately or causes a
segmentation fault?
Enter the following to recompile
FIFOtrigger. Also, the source code for FIFOtrigger is available for
editing and viewing at
PCI-SERIAL directory.
linux PCI-SERIAL# gcc -O FIFOtrigger_pci.c -o
linux PCI-SERIAL# ./FIFOtrigger <
FIFOtrigger_pci.c provided in the
FIFOtrigger
<
FIFOtrigger_pci.c and rerun
port number
rx_trigger
> <
tx_trigger
>
>
What do I do if rs485 does not work immediately?
Enter the following to recompile
rs485 is available for editing and viewing at rs385.c, provided in the
PCI-SERIAL directory.
linux PCI-SERIAL# gcc -O rs485.c -o rs485
rs485.c. Also, the source code for
What do I do if clockspeed does not work immediately or if it causes
a segmentation fault?
Enter the following to recompile
clockspeed. Also, the source code for clockspeed is available for
editing and viewing at
clock_speed.c, provided in the PCI-SERIAL
clock_speed.c and rerun
directory.
linux PCI-SERIAL# gcc -O clock_speed.c -o clockspeed
linux PCI-SERIAL# ./clockspeed <
port number
> <
high/low
>
What do I do if serialtest does not work immediately or if it causes
a segmentation fault?
Enter the following to recompile
Also, the source code for
at
serialtest.c, provided in the PCI-SERIAL directory.
linux PCI-SERIAL# gcc serialtest.c -o serialtest
linux PCI-SERIAL# ./serialtest <
serialtest is available for editing and viewing
<
serialtest.c and rerun serialtest.
receive port number
transmit port number
>
>
What do I do if serialtest hangs?
Make sure the interface is seated correctly and tighten the scre w that holds
the interface in place. Also, make sure the cables are attached to the correct
ports. In some cases,
serialtest hangs if the transceiver modes
(PCI-485) are not set. Try setting both transmit and receive ports to
transceiver mode 0 (Four-Wire Mode).
What do I do if my ports are not communicating correctly and print
strange characters?
Make sure the baud rate, character size, clock speed (if PCI-485) and parity
are the same for both the receiver and transmitter. Also make sure the
transceiver modes (PCI-485) have been selected for both transceivers.
Assign Driver
How can I use
/dev/ttyS3 as National Instruments serial ports?
/dev/ttyS0, /dev/ttyS1, /dev/ttyS2, or
Check for available serial devices by entering the following:
# Changed for the two-port PCI-SERIAL interface.
#
${SETSERIAL} /dev/ttyS4 uart 16550A port 0xdff0 irq 11 ^fourport
${SETSERIAL} /dev/ttyS5 uart 16550A port 0xdfe0 irq 11 ^fourport
###########################################################
#
# Print the results of the serial configuration process
#
###########################################################