Com port is all about it. Serial port

). Despite the fact that some computer interfaces (for example, Ethernet, FireWire and USB) also use a serial method of exchanging information, the name “serial port” is assigned to the RS-232 standard port.

Encyclopedic YouTube

  • 1 / 5

    The most commonly used standard for the serial port of personal computers is RS-232C. Previously, the serial port was used to connect a terminal, later for a modem or mouse. It is now used to connect to hardware for the development of embedded computing systems, satellite receivers, cash registers, security systems, and many other devices.

    Using a COM port, you can connect two computers using a so-called “null modem cable” (see below). It has been used since the days of MS-DOS for transferring files from one computer to another, in UNIX for terminal access to another machine, and in Windows (even modern ones) for a kernel-level debugger.

    The advantage of the technology is the extreme simplicity of the equipment. The disadvantage is the low speed, large size of the connectors, as well as often high requirements for the response time of the OS and driver and a large number of interrupts (one per half of the hardware queue, that is, 8 bytes).

    Connectors

    On motherboards from leading manufacturers (for example, Intel) or ready-made systems (for example, IBM, Hewlett-Packard, Fujitsu Siemens Computers), the following symbol is used for the serial port:

    The most commonly used D-shaped connectors, standardized in 1969, are 9- and 25-pin, (DE-9 and DB-25, respectively). Previously, DA-31 and round eight-pin DIN-8 were also used. The maximum transmission speed in the normal version of the port is 115,200 baud.

    Relevance

    There are standards for emulating a serial port over USB and over Bluetooth (this technology was largely designed as a “wireless serial port”).

    Nevertheless, software emulation of this port is still widely used today. For example, almost all mobile phones emulate a classic COM port and modem within themselves to implement tethering - computer access to the Internet via the phone’s GPRS/EDGE/3G equipment. In this case, USB, Bluetooth or Wi-Fi are used for physical connection to the computer.

    Also, software emulation of this port is provided to “guests” of VMWare and Microsoft Hyper-V virtual machines, the main purpose of which is to connect a Windows kernel-level debugger to the “guest”.

    In the form of a UART, which differs in voltage levels and the absence of additional signals, it is present in almost all microcontrollers, except the very small ones, SoC, developer boards, and is also present on the boards of most devices, but the connector is not located on the case. This popularity is due to the simplicity of this interface, both from a physical point of view and the ease of access to the port from the software compared to other interfaces.

    Equipment

    The connector has contacts:

    DTR (Data Terminal Ready - readiness to receive data) - output on the computer, input on the modem. Indicates that the computer is ready to use the modem. Resetting this line causes an almost complete reboot of the modem to its original state, including hanging up (some control registers survive such a reset). On UNIX, this occurs when all applications have closed files on the serial port driver. The mouse uses this wire to receive power.

    DSR (Data Set Ready - readiness for data transfer) - input on the computer, output on the modem. Indicates that the modem is ready. If this line is at zero, then in some operating systems it becomes impossible to open the port as a file.

    RxD (Receive Data) - input on the computer, output on the modem. A stream of data entering a computer.

    TxD (Transmit Data - data transfer) - output on the computer, input on the modem. A stream of data coming from a computer.

    CTS (Clear to Send - readiness to send) - input on the computer, output on the modem. The computer is required to suspend data transmission until this wire is set to one. Used in the hardware flow control protocol to prevent overflow in the modem.

    RTS (Request to Send - request to send) - output on the computer, input on the modem. The modem is required to suspend data transmission until this wire is set to one. Used in hardware flow control protocol to prevent hardware and driver overflows.

    DCD (Carrier Detect - presence of carrier) - input on the computer, output on the modem. Set to one by the modem after establishing a connection with the modem on the other side, reset to zero when the connection is broken. The computer hardware may issue an interrupt when such an event occurs.

    RI (Ring Indicator - ringing signal) - input on the computer, output on the modem. Set by the modem to one after detecting the ringing signal of a telephone call. The computer hardware may issue an interrupt when such an event occurs.

    SG (Signal Ground) - common signal wire of the port, is not common land, as a rule, isolated from the computer case or modem.

    A null modem cable uses two crossed pairs: TXD/RXD and RTS/CTS.

    Initially, in the IBM PC and IBM PC/XT, the port equipment was built on the UART 8250 chip from National Semiconductor, then the chip was replaced by the 16450, software compatible with the previous ones, but allowing speeds up to 115,200 bits per second, then the 16550 chip appeared, containing bidirectional FIFO data buffer to reduce the load on the interrupt controller. Currently included in the SuperIO chip on the motherboard along with a number of other devices.

    Sometimes you have to solve the problem of connecting an electronic device with a computer, be it simply data exchange or remote control. This article describes how this can be implemented using a serial port. Its main advantage is that the standard Windows programming interface (API) allows direct control of the output lines, giving direct control over them, and has the function of waiting for some event associated with the COM port. Also, the RS-232 standard, according to which the COM ports are made, allows for connecting and disconnecting cables while the devices are operating (hot plug).

    Description

    COM port (serial port)– bidirectional interface that transmits data in serial form (bit by bit) via the RS-232 protocol. This is a fairly common protocol used to connect one device (for example, a computer) with others via wires up to 30 m long. The logical signal levels here differ from the standard ones: the logical one level is from +5 to +15V, the logical zero level is from -5 to -15V, which requires additional circuit transformations, but provides good noise immunity.

    Consider a 9-pin connector (DB-9M). Below is its pinout:

    Pin no. Name Character of the signal Signal
    1 DCD Input Data carrier detect
    2 RxD Day off Transmit data
    3 TxD Input Receive data
    4 DTR Day off Data terminal ready
    5 GND - Ground
    6 DSR Input Data set ready
    7 RTS Day off Request to send
    8 CTS Input Clear to send
    9 R.I. Input Ring indicator

    We will be most interested in pins 2 (data transmission), 3 (data reception) and 5 (ground). This is the minimum set for two-way communication between devices.

    I will not dwell on the description of the protocol in detail. For this there are GOSTs, etc. Therefore, we will go further and talk about how to control this beast.

    Application

    As already mentioned, RS-232 LAN levels are different from standard TTL levels. Therefore, we need to somehow convert the voltage values. Those. make 5V from +15V and 0V from -15V (and vice versa). One way (and probably the simplest) is to use a special MAX232 chip. It is easy to understand and can simultaneously convert two logic signals.

    Below is a diagram of its inclusion:


    I think there shouldn't be any difficulties. This is one of the options for using this chip: transferring data from a microcontroller to a computer and vice versa. The transmitted signal goes to the T pins x IN on one side and on R x IN on the other. Input signals are taken from T x OUT and R x OUT accordingly.

    Programming

    First, let's talk about programming ports at a low level. This will be more correct. I spent a lot of nerves understanding this interface until I began to delve into the principle of its operation at a lower level than simple character transmission. If this is clear, then there will be no problems with high-level languages.

    Below are the addresses of the COM ports that we will have to work with:

    Port name Address IRQ
    COM 1 3F8h 4
    COM 2 2F8h 3
    COM 3 3E8h 4
    COM 4 2E8h 3

    They may vary. You can set the values ​​in the BIOS settings. These are the base addresses. The addresses of the registers responsible for the operation of the ports will depend on them:

    Address DLAB Read/Write Abbreviation Register name
    + 0 =0 Write Transmitter Holding Buffer
    =0 Read Receiver Buffer
    =1 Read/Write Divisor Latch Low Byte
    + 1 =0 Read/Write IER Interrupt Enable Register
    =1 Read/Write Divisor Latch High Byte
    + 2 - Read IIR Interrupt Identification Register
    - Write FCR FIFO Control Register
    + 3 - Read/Write LCR Line Control Register
    + 4 - Read/Write MCR Modem Control Register
    + 5 - Read LSR Line Status Register
    + 6 - Read MSR Modem Status Register
    + 7 - Read/Write Scratch Register

    The first column is the register address relative to the base one. For example, for COM1: the LCR register address will be 3F8h+3=3FB. The second column is DLAB (Divisor Latch Access Bit) bit, which defines different purposes for the same register.. I.e. it allows you to operate 12 registers using only 8 addresses. For example, if DLAB=1, then by accessing address 3F8h we will set the value of the low byte of the clock generator frequency divider. If DLAB = 0, then when accessing the same address, the transmitted or received byte will be written to this register.

    “Zero” register

    It corresponds to registers for receiving/transmitting data and setting the generator frequency divider coefficient. As mentioned above, if DLAB = 0, then the register is used to record received/transmitted data, but if it is equal to 1, then the value of the low byte of the clock generator frequency divider is set. The data transmission speed depends on the value of this frequency. The high byte of the divider is written to the next memory cell (i.e. for the COM1 port it will be 3F9h). Below is the dependence of the data transfer rate on the divisor coefficient:

    Interrupt Enable Register (IER)

    If DLAB=0, then it is used as a register for controlling interrupts from an asynchronous adapter; if DLAB=1, then the high byte of the clock generator frequency divider is set in it.

    Interrupt Identification Register (IIR)

    An interrupt is an event that stops the execution of the main program and begins the execution of the interrupt routine. This register determines the type of interrupt that occurred.

    Line Control Register (LCR)

    This is the control register.

    Bit 7 1 Divisor Latch Access Bit – setting the data exchange speed
    0 Normal mode (interrupt control, data reception/transmission)
    Bit 6 Simulate line break (sends a sequence of multiple zeros)
    Bits 3 – 5 Bit 5 Bit 4 Bit 3 Parity selection
    X X 0 No Parity
    0 0 1 Odd Parity
    0 1 1 Even Parity
    1 0 1 High Parity (Sticky)
    1 1 1 Low Parity (Sticky)
    Bit 2 Number of stop bits
    0 1 stop bit
    1 2 stop bits for 6,7 or 8 data bits or 1.5 stop bits for 5 data bits.
    Bits 0 And 1 Bit 1 Bit 0 Number of data bits
    0 0 5 bits
    0 1 6 bit
    1 0 7 bit
    1 1 8 bit

    Parity checking involves the transmission of one more bit - the parity bit. Its value is set so that the total number of ones (or zeros) in a packet of bits is even or odd, depending on the setting of the port registers. This bit is used to detect errors that may occur during data transmission due to interference on the line. The receiving device recalculates the parity of the data and compares the result with the received parity bit. If the parity does not match, then it is considered that the data was transmitted with an error.

    The stop bit indicates the end of data transmission.

    Modem Control Register (MCR)

    Modem control register.

    Bit Meaning
    0 DTR line
    1 RTS line.
    2 Line OUT1 (spare)
    3 Line OUT2 (spare)
    4 Running diagnostics when the input of an asynchronous adapter is shorted to its output.
    5-7 Equal to 0

    Line Status Register (LSR)

    A register that determines the state of the line.

    Bit Meaning
    0 Data received and ready to be read, automatically reset when data is read.
    1 Overflow error. A new byte of data was received, but the previous one had not yet been read by the program. The previous byte is lost.
    2 Parity error, cleared after reading line status.
    3 Synchronization error.
    4 A request to interrupt transmission "BREAK" was detected - a long string of zeros.
    5 The transmitter holding register is empty and a new byte can be written to it for transmission.
    6 The transmitter shift register is empty. This register receives data from the holding register and serializes it for transmission.
    7 Timeout (device is not connected to the computer).

    Modem Status Register (MSR)

    Modem status register.

    OK it's all over Now. By operating these registers, you can directly communicate with the COM port and control the transmission and reception of data. If you don’t want to tinker with memory, you can use ready-made components for various programming environments: C++, VB, Delphi, Pascal, etc. They are intuitive, so I think there is no need to focus on them here.

    So we got to the COM port. But with it everything is not as simple as with LPT, and its full use will require much more effort. The main problem is also its main advantage - serial data transfer. If in LPT a byte of data is transmitted along 8 lines, a bit per line, and the state of each line could be easily viewed, then in the COM port a byte of data is transmitted bit by bit along one line (relative to ground, of course) and see what is transmitted there with LEDs alone won't do it. To do this, you need a special device - a converter of a serial data stream into a parallel one, the so-called. USART (Universal Synchronous/Asynchronous Receiver Transmitter). For example, it is included in the motherboard of a computer equipped with a COM port, or in any more serious microcontroller.


    I hope you are still discouraged in mastering the COM port. It's not all doom and gloom. Some results can be obtained without USART. Let us formulate a task that we will implement at the initial stage of working with the COM port:


    "I would like an LED to be connected to the computer via the COM port. I launch the program. I perform some action in this program, the LED lights up, I do something else - the LED goes out."


    The task is quite specific (taking into account the fact that USART is not used) and is a pure “do-it-yourself” task, but it is quite feasible and workable. Let's start implementing it.


    1.COM port

    Again, take the system unit of your PC and look at the rear. We note there is a 9-pin connector - this is the COM port. In reality there may be several of them (up to 4). My PC has two COM ports (see photo).


    2. COM port extension


    3. Hardware

    We will also have to “tinker” with the hardware, in the sense that it will be more complicated than with the first device for the LPT port. The fact is that the RS-232 protocol, through which data is exchanged in the COM port, has a slightly different logical state-voltage relationship. If usually this is logical 0 0 V, logical 1 +5 V, then in RS-232 this relationship is as follows: logical 0 +12 V, logical 1 -12 V.

    And for example, having received -12 V, it is not immediately clear what to do with this voltage. Typically, RS-232 levels are converted to TTL (0.5 V). The simplest option is zener diodes. But I propose to make this converter on a special chip. It's called MAX232.

    Now let's see what signals from the COM port can we see on the LEDs? In fact, there are as many as 6 independent lines in the COM port, which are of interest to the developer of interface devices. Two of them are not yet available to us - serial data lines. But the remaining 4 are designed to control and indicate the data transfer process and we can “transfer” them to suit our needs. Two of them are intended for control from an external device and we will not touch them for now, but we will now use the last two remaining lines. They're called:

    • RTS- Request for transfer. An interaction line that indicates that the computer is ready to receive data.
    • DTR- The computer is ready. An interaction line that indicates that the computer is turned on and ready to communicate.

    Now we transfer their purpose a little, and the LEDs connected to them will either go out or light up, depending on the actions in our own program.

    So, let's put together a diagram that will allow us to carry out our intended actions.

    And here is its practical implementation. I think you will forgive me that I made it in such a dumb breadboard version, because I don’t want to make a board for such a “highly productive” circuit.


    4. Software part

    Everything is simpler here. Let's create a Windows application in Microsoft Visual C++ 6.0 based on MFC to manage two lines of COM port communication. To do this, create a new MFC project and give it a name, for example, TestCOM. Next, select the option of constructing based on dialogue.

    Give the appearance of our program's dialog window as in Fig. below, namely add four buttons, two for each of the lines. One of them is respectively necessary to “extinguish” the line, the other to “set” it to one.

    Class CTestCOMDlg: public CDialog ( // Construction public: CTestCOMDlg(CWnd* pParent = NULL); // standard constructor HANDLE hFile;

    In order for our program to control the lines of a COM port, it must first be opened. Let's write the code responsible for opening the port when loading the program.

    HFile = CreateFile("COM2", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,NULL); if(hFile==INVALID_HANDLE_VALUE) ( MessageBox("The port could not be opened!", "Error", MB_ICONERROR); ) else ( MessageBox("The port was successfully opened", "Ok", MB_OK); )

    Using the standard Win API function CreateFile() open the COM port COM2. Next, we check the success of the opening and display an information message. Here we need to make an important note: COM2 is on my computer, but on your computer you could connect it to another COM port. Accordingly, its name needs to be changed to whatever port you are using. You can see what port numbers are present on your computer like this: Start -> Settings -> Control Panel -> System -> Hardware -> Device Manager -> Ports (COM and LPT).

    As a result, the function CTestCOMDlg::OnInitDialog(), located in the file TestCOMDlg.cpp, our dialogue class should take the form:

    BOOL CTestCOMDlg::OnInitDialog() ( CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); ) ) // Set the icon for this dialog. The framework does this automatically // when the application"s main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here hFile = CreateFile("COM2", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,NULL); if(hFile==INVALID_HANDLE_VALUE) ( MessageBox("Could not open port!", "Ostbk", MB_ICONERROR); ) else ( MessageBox("Port successfully opened", "Ok", MB_OK); ) return TRUE; // return TRUE unless you set the focus to a control )

    Now let's add handlers for line control buttons. I gave them appropriate names: the function that sets one on the DTR line is OnDTR1(), 0 is OnDTR0(). For the RTS line, in the same way. Let me remind you that the handler is created when you double click on the button. As a result, these four functions should take the form:

    Void CTestCOMDlg::OnDTR1() ( // TODO: Add your control notification handler code here EscapeCommFunction(hFile, 6); ) void CTestCOMDlg::OnDTR0() ( // TODO: Add your control notification handler code here EscapeCommFunction(hFile, 5); ) void CTestCOMDlg::OnRTS1() ( // TODO: Add your control notification handler code here EscapeCommFunction(hFile, 4); ) void CTestCOMDlg::OnRTS0() ( // TODO: Add your control notification handler code here EscapeCommFunction(hFile, 3);

    Let me explain a little how they work. As you can see, inside they contain a call to the same Win API function EscapeCommFunction() with two parameters. The first of them is a handle (HANDLE) to an open port, the second is a special action code corresponding to the required state of the line.

    That's it, we compile and launch. If everything is fine, you should see a message about the successful opening of the port. Next, by pressing the corresponding buttons, we blink the LEDs connected to the COM port.

    © Ivanov Dmitry
    December 2006

    Along with the parallel port, the COM port, or serial port, is one of the traditional computer input/output ports, used in the first PCs. Although the COM port has limited use in modern computers, nevertheless, information about it may be useful to many users.

    The serial port, like the parallel port, appeared long before the advent of personal computers of the IBM PC architecture. In the first personal computers, the COM port was used to connect peripheral devices. However, the scope of its application was somewhat different from the scope of the parallel port. If the parallel port was used mainly to connect printers, then the COM port (by the way, the prefix COM is just an abbreviation for the word communication) was usually used to work with telecommunications devices, such as modems. However, you can connect to the port, for example, a mouse, as well as other peripheral devices.

    COM port, main areas of application:

    1. Connecting terminals
    2. ~ external modems
    3. ~ printers and plotters
    4. ~ mice
    5. Direct connection between two computers

    Currently, the scope of the COM port has been significantly reduced due to the introduction of a faster and more compact, and, by the way, also serial, USB interface. External modems designed to connect to a port, as well as “COM” mice, have almost gone out of use. And it’s rare that anyone now connects two computers using a null modem cable.

    However, a number of specialized devices still use the serial port. You can find it on many motherboards. The fact is that, compared to USB, a COM port has one important advantage - according to the RS-232 serial data transmission standard, it can work with devices at a distance of several tens of meters, while the range of a USB cable is usually limited to 5 meters.

    The principle of operation of a serial port and its difference from a parallel one

    Unlike a parallel (LPT) port, a serial port transmits data bit by bit on a single line, rather than on several lines at the same time. Sequences of bits are grouped into series of data, starting with a start bit and ending with a stop bit, as well as parity bits used for error checking. This is where another English name comes from, which has a serial port - Serial Port.

    The serial port has two lines through which the actual data is transmitted - these are lines for transferring data from the terminal (PC) to the communication device and back. In addition, there are several more control lines. The Serial port is served by a special UART chip, which is capable of supporting a relatively high data transfer rate, reaching 115,000 baud (bytes/s). However, it is worth noting that the actual speed of information exchange depends on both communication devices. In addition, the functions of the UART controller include converting parallel code into serial code and vice versa.

    The port uses comparatively high voltage electrical signals - up to +15 V and -15 V. The logical zero level of the serial port is +12 V, and the logical one level is -12 V. Such a large voltage drop allows us to guarantee a high degree of noise immunity of the transmitted data. On the other hand, the high voltages used in Serial port require complex circuit solutions. This circumstance also contributed to the decline in the popularity of the port.

    Serial interface RS-232

    Serial port operation on a PC is based on the data transmission standard for serial devices RS-232. This standard describes the process of data exchange between a telecommunications device, such as a modem, and a computer terminal. The RS-232 standard defines the electrical characteristics of signals, their purpose, duration, as well as the sizes of connectors and pinouts for them. However, RS-232 describes only the physical level of the data transfer process and does not concern the transport protocols used, which may vary depending on the communication equipment and software used.

    The RS-232 standard was created in 1969, and its latest version, TIA 232, was released in 1997. RS-232 is now considered obsolete, but most operating systems still support it.

    In modern computers, the Serial port connector is a 9-pin DB-9 male connector, although the RS-232 standard also describes a 25-pin DB-25 connector, which was often used on older computers. The DB-9 connector is usually located on the PC motherboard, although in older computers it may have been located on a special multicard inserted into an expansion slot.

    9-pin DB-9 socket on motherboard

    DB-9 connector on the cable of the device connected to the port

    Unlike a parallel port, the connectors on both sides of a two-way serial cable are identical. In addition to the lines for transmitting the data itself, the port contains several service lines through which control information can be transmitted between the terminal (computer) and the telecommunications device (modem). Although theoretically only three channels are needed for a serial port to operate - data reception, data transmission and ground, practice has shown that the presence of service lines makes communication more efficient, reliable and, as a result, faster.

    Purpose of the Serial port DB-9 connector lines according to RS-232 and their correspondence to the contacts of the DB-25 connector:

    Contact DB-9 English name Russian name Contact DB-25
    1 Data Carrier Detect Carrier detected 8
    2 Transmit Data Transmitted data 2
    3 Receive Data Received data 3
    4 Data Terminal Ready Terminal readiness 20
    5 Ground Earth 7
    6 Data Set Ready Transmitter readiness 6
    7 Request To Send Request to send data 4
    8 Clear To Send Data transfer allowed 5
    9 Ring Indicator Ring indicator 22

    Configuration and interrupts

    Since a computer can have several serial ports (up to 4), the system allocates two hardware interrupts for them - IRQ 3 (COM 2 and 4) and IRQ 4 (COM 1 and 3) and several BIOS interrupts. Many communication programs, as well as built-in modems, use interrupts and the address space of COM ports for their work. In this case, not real ports are usually used, but so-called virtual ports, which are emulated by the operating system itself.

    As with many other motherboard components, the COM port parameters, in particular the BIOS interrupt values ​​corresponding to hardware interrupts, can be configured through the BIOS Setup interface. For this, BIOS options such as COM Port, Onboard Serial Port, Serial Port Address, etc. are used.

    Conclusion

    The PC serial port is not currently a widely used means of input/output. However, since there is a large amount of equipment, primarily for telecommunications purposes, designed to work with a serial port, and also due to some of the advantages of the RS-232 serial data protocol, the serial interface should not yet be written off as a completely outdated rudiment personal computer architecture.

    Description of the RS-232 interface, the format of the connectors used and the purpose of the pins, signal designations, data exchange protocol.

    general description

    The RS-232 interface, officially called "EIA/TIA-232-E", but better known as the "COM port" interface, was previously one of the most common interfaces in computer technology. It is still found on desktop computers, despite the advent of faster and smarter interfaces such as USB and FireWare. Its advantages from the point of view of radio amateurs include the low minimum speed and ease of implementation of the protocol in a homemade device.

    The physical interface is implemented by one of two types of connectors: DB-9M or DB-25M, the latter is practically not found in currently produced computers.

    Pin assignment of the 9-pin connector


    DB-9M type 9-pin plug
    Numbering of contacts on the pin side
    The direction of the signals is indicated relative to the host (computer)
    Contact Signal Direction Description
    1 CD Entrance Carrier detected
    2 RXD Entrance Received data
    3 TXD Exit Transmitted data
    4 DTR Exit Host ready
    5 GND - Common wire
    6 DSR Entrance Device is ready
    7 RTS Exit The host is ready to transmit
    8 CTS Entrance The device is ready to receive
    9 R.I. Entrance Call detected

    Pin assignment of the 25-pin connector

    Contact Signal Direction Description
    1 S.H.I.E.L.D. - Screen
    2 TXD Exit Transmitted data
    3 RXD Entrance Received data
    4 RTS Exit The host is ready to transmit
    5 CTS Entrance The device is ready to receive
    6 DSR Entrance Device is ready
    7 GND - Common wire
    8 CD Entrance Carrier detected
    9 - - Reserve
    10 - - Reserve
    11 - - Not used
    12 SCD Entrance Carrier #2 detected
    13 SCTS Entrance Device is ready to receive #2
    Contact Signal Direction Description
    14 STXD Exit Transmitted data #2
    15 TRC Entrance Transmitter clocking
    16 SRXD Entrance Received data #2
    17 RCC Entrance Receiver clocking
    18 LLOOP Exit Local loop
    19 SRTS Exit Host ready to transmit #2
    20 DTR Exit Host ready
    21 RLOOP Exit External loop
    22 R.I. Entrance Call detected
    23 DRD Entrance Data speed determined
    24 TRCO Exit External transmitter clocking
    25 TEST Entrance Test mode

    From the tables it can be seen that the 25-pin interface is distinguished by the presence of a full-fledged second transmit-receive channel (signals designated “#2”), as well as numerous additional control and control signals. However, often, despite the presence of a “wide” connector in the computer, additional signals are simply not connected to it.

    Electrical characteristics

    Transmitter logic levels:"0" - from +5 to +15 Volts, "1" - from -5 to -15 Volts.

    Receiver logic levels:"0" - above +3 Volts, "1" - below -3 Volts.

    The receiver input impedance is at least 3 kOhm.

    These characteristics are defined by the standard as minimal, guaranteeing the compatibility of devices, however, the real characteristics are usually much better, which allows, on the one hand, to power low-power devices from the port (for example, numerous homemade data cables for cell phones are designed this way), and, on the other hand, to supply to the port input inverted TTL level instead of bipolar signal.

    Description of the main interface signals

    CD- The device sets this signal when it detects a carrier in the received signal. Typically, this signal is used by modems, which thus inform the host that they have detected a working modem at the other end of the line.

    RXD- Line for the host to receive data from the device. Described in detail in the "Data exchange protocol" section.

    TXD- Data line from the host to the device. Described in detail in the "Data exchange protocol" section.

    DTR- The host sets this signal when it is ready to exchange data. In fact, the signal is set when the port is opened by the communications program and remains in this state as long as the port is open.

    DSR- The device sets this signal when it is turned on and ready to communicate with the host. This and the previous (DTR) signals must be set for data exchange.

    RTS- The host sets this signal before starting to transmit data to the device, and also signals that it is ready to receive data from the device. Used for hardware control of data exchange.

    CTS- The device sets this signal in response to the host setting the previous one (RTS) when it is ready to receive data (for example, when the previous data sent by the host is transferred by the modem to the line or there is free space in the intermediate buffer).

    R.I.- The device (usually a modem) sets this tone when it receives a call from a remote system, for example when receiving a telephone call if the modem is configured to receive calls.

    Communication protocol

    In the RS-232 protocol, there are two methods for controlling data exchange: hardware and software, as well as two transmission modes: synchronous and asynchronous. The protocol allows you to use any of the control methods in conjunction with any transmission mode. It is also possible to operate without flow control, which means that the host and device are always ready to receive data when communication is established (DTR and DSR signals are established).

    Hardware control method implemented using RTS and CTS signals. To transmit data, the host (computer) sets the RTS signal and waits for the device to set the CTS signal, and then begins transmitting data as long as the CTS signal is set. The CTS signal is checked by the host immediately before the next byte begins to be transmitted, so a byte that has already begun to be transmitted will be transmitted in full, regardless of the CTS value. In half-duplex data exchange mode (the device and the host transmit data in turn, in full-duplex mode they can do this simultaneously), the removal of the RTS signal by the host means it switches to receive mode.

    Software control method consists of the receiving side transmitting special stop (character with code 0x13, called XOFF) and resume (character with code 0x11, called XON) transmissions. When these characters are received, the sending party must stop the transmission or resume it accordingly (if there is data waiting to be transmitted). This method is simpler in terms of hardware implementation, but provides a slower response and, accordingly, requires advance notification of the transmitter when the free space in the receive buffer is reduced to a certain limit.

    Synchronous transmission mode implies continuous data exchange when bits follow one after another without additional pauses at a given speed. This mode is COM port not supported.

    Asynchronous transfer mode consists in the fact that each byte of data (and parity bit, if present) is “wrapped” with a synchronizing sequence of one zero start bit and one or more one stop bits. The data flow diagram in asynchronous mode is shown in the figure.

    One of the possible receiver operation algorithms next:

    1. Wait for the receive signal level "0" (RXD in the case of a host, TXD in the case of a device).
    2. Count half the bit duration and check that the signal level is still "0"
    3. Count the full duration of the bit and write the current signal level to the least significant bit of data (bit 0)
    4. Repeat previous step for all remaining data bits
    5. Count the full duration of the bit and the current signal level, use it to check correct reception using parity check (see below)
    6. Count the full duration of the bit and make sure that the current signal level is “1”.