Serial port. COM port. Pairing devices with PC. Programming

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.

A special feature of this port compared to other “serial” technologies is the fact that there are no timing requirements between 2 bytes. There are timing requirements only between the bits of one byte (including start, stop and parity), the reciprocal of the time pause between the bits of one byte is called the baud rate - the baud rate. Also in this technology there is no concept of “package”.

Other "serial" technologies, such as X.25, USB or Ethernet, have a "packet" concept, and impose strict timing requirements between all bits of a single packet.

For this reason, in Cisco IOS terminology, this port was called async - in contrast to synchronous serial, i.e. X.25. For the same reason, the Windows module that implements PPP over this port is called AsyncMac.sys (the PPP standard separately describes the implementation of PPP, which uses the concept of “packet”, over a serial port that does not have this concept).

Some industrial communications protocols impose strict timing requirements between serial port bytes. Such protocols are extremely difficult to implement in multitasking operating systems with weak real-time support, such as Windows, and therefore often require MS-DOS and outdated software from almost 20 years ago on the control computer.

Purpose

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, to communicate with hardware for the development of embedded computing systems, satellite receivers, cash registers, as well as with facility security system 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 low speed, large connector sizes, as well as often high requirements for the response time of the OS and driver and a high number of interrupts (one per half of the hardware queue, i.e. 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-pin and 25-pin (DB-9 and DB-25, respectively). Previously, DB-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/EGDE/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”.

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, incl. 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.

The standard (since the original IBM PC) port hardware is called UART 16550 (currently included in the SuperIO chip on the motherboard along with a number of other devices). Since the time of the IBM PC, a hardware byte queue has appeared in it, which greatly reduces the number of interrupts issued by the device.

Programmatic access to the COM port

UNIX

There is a registry section for each port. These sections have the following names:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Serial\Parameters\Serial10000

where the last value “Serial10000” is a unique number for each new COM port added to the system, for the second one – “Serial10001”, etc.

To communicate with devices that support Bluetooth, some programs (for example, such programs include: a program that synchronizes the contact list with a mobile phone; a program that retrieves GPS coordinates from a GPS receiver) requires a COM port on the user's computer.

Programs that use COM ports to support communication using Bluetooth wireless technology, directly developed by Microsoft, include:

  • HotSync used in handheld computers
  • ActiveSync, used in pocket PCs

OS/2

The existing COM.SYS driver supports only 4 COM ports, each of which must have its own interrupt line. To service COM ports with a common interrupt line, you must use the SIO driver.

Null modem cable

Main article: Null modem cable

In some cases, it is possible to use a simplified version of the cable, in which only pins 2, 3 and 5 are used.

see also

  • Serial Port Signals

Notes

Links

  • Translation of the COM port programming guide in POSIX operating systems
  • Programming the port in java - allows you to work from Windows, unlike official packages from Sun.
  • Programming a COM port in C++ for Windows. Ready-made library, source codes, sample programs.
  • Yashkardin V.L. Serial port. Programming a COM port in Windows and MS-DOS. SoftElectro (2009). Archived from the original on February 8, 2012.

Greetings, friends. We continue to study the system unit. Today I’ll talk about computer ports. What it is? With the rapid development of Internet technologies, the concept of “port” or “socket” is familiar to many. This is another branch, and we will not talk about it today. The topic of this article contains information about purely “hard”, “real” connectors (or ports), which are designed to connect various devices to the system unit.

Hardware is also improving, and with each generation we discover new types of connectors (or ports) on purchased system units. Various so-called peripheral devices are connected to them. System unit + monitor = computer. Everything that is connected to them (printers, scanners, programmers, video cards, monitors, and so on) is a peripheral.

There are many ports on a computer. They are located on the motherboard of the system unit and are connectors (most of them are on the back). Some of the connectors are also displayed on the front panel and they are also connected to the motherboard.

You can also install additional devices on it through special expansion slots. Such devices include discrete video cards, network cards, Wi-Fi adapters, USB hubs, card readers, electronic locks, video cards and much more.

The presence of expansion slots allows you to independently assemble a computer like a construction set, based on your preferences, without spending an extra day. Because the developers have long standardized the equipment they produce. If necessary, you can update it. This is the main reason that IBM-PC compatible computers (as this platform is called) once ousted the Apple Macintosh from the market.

Their system units were initially non-separable, and the equipment was not replaceable. It is impossible to upgrade such a device, and the maintainability of such a device is reduced.

A short list of computer ports

You need to be able to distinguish connectors from one another visually. The manufacturer does not always indicate their names. Since the connectors are grouped on the rear panel of the system unit, we’ll start there. All ports have an English name, nothing can be done about it. They can be briefly divided:

  1. Serial ports;
  2. Parallel port;
  3. Ports for computer and mouse;
  4. USB ports;
  5. SCSI ports;
  6. Video ports;
  7. Network cable connectors;
  8. Audio connectors;
  9. Card readers;

Some of these varieties have already sunk into oblivion and can no longer be found on modern motherboards. Other varieties, on the contrary, expand their functionality and there are motherboards for gourmets - lovers of good quality audio or video.


Such boards can also support audio or video formats from third-party manufacturers (Sony, Philips), and then you can find a corresponding connector on such a computer. Audio and video ports today boast a particular variety.

Computer ports for connecting peripheral devices

Serial port- today it is already a morally outdated thing. But for specialists who repair electronic devices, they are valuable. Initially, this port was used to connect a modem. Typical data transfer rates range from 110 to 115,200 bits per second. There were usually two of them with connectors DB 9 type "dad":

The speed is quite enough for the programmer to flash a microcontroller or mobile phone. Or to exchange data with an uninterruptible power supply. These ports are called COM1 And COM2.

Parallel port- is familiar to many, because it was mainly intended for connecting a printer. Also an almost extinct species. It was also used to connect hardware security keys.


The connector is used for connection DB25 like "mom". The data transfer speed is low - but quite enough for a programmer or an old laser printer. Most old computers always had two serial ports and one parallel port.

Keyboard and mouse ports familiar to all users. In modern computers they are purple and green. The plugs on the mouse and keyboard are the same color. It's difficult to confuse. The connectors are six-pin (mini-Din) female type. They were invented in Germany and it became the standard. Another name for IBM/PC2

since they were first used on the already mentioned IBM PC platform. If the connectors are mixed up when connecting, the devices will not work. A definite plus is that USB ports save money. Minus - you must restart the computer if it is connected incorrectly. By the way, it is also an endangered species. On many modern computers, this port is left only one - and it is also painted purple-green. You can connect only one device or mouse or keyboard to it.

USB ports. Universal serial bus, ( Universal Serial Bus). Since 1998, it has been displacing other ports; Even on car radios and video cameras today you will find this connector. The first generations had a data transfer speed of about 12 MB/sec. - mind-blowing for those times. Today we use USB 3, which has a speed of 5 Gbps

These ports have not changed in appearance. The computer has type A connectors. The connector on any connected device is usually called “B”. It has four contacts, two for current, two for data transmission. Accordingly, there are twice as many pins on USB 3.0 ports.

SCSI ports(Small Computer Systems Interface) . Quite a specific and rare thing for us; I think that even abroad you will no longer find it among the average user. I believe that devices with such interfaces were made to order - for corporate use. This is a network interface for data exchange at speeds up to 160 Mbit/s.


I once came across a laptop brought from America, manufactured in 1999, from Dell. It had one of those multi-pin ports. It was located in such a way that it could only be used by placing the laptop on the table. The connector itself is closed with curtains on springs. Consequently, somewhere in America there were tables in which this connector was built in... You bring it, put it on the table, and it is connected to the corporate network.

The interface varieties are already familiar to us DB-25, as well as 50-High-Density, 68-pin -High-Density, 80-pin SCA, Centronics. It was also possible to connect hard drives to this interface. A special board, the host adapter, is responsible for the connection.


Video ports. They also cannot be confused with others. The standard video port is a 15-pin VGA blue D-type female connector. Used to connect a monitor. This is an old standard, adopted in 1987. Not all motherboards have it. If you don’t have it “on board”, then it can be found at the bottom of the system unit. A video card is installed in the expansion slot:

If you decide to install a video card in addition to the one you already have (“on board”), then the latter will no longer work. This is fine. The monitor will only work when connected to an installed one.

On modern video cards, the VGA port has become difficult to find; they are being replaced by another type - DVI. On a transition type motherboard it looks something like this:

Very often there are cases when a VGA video card fails. After purchasing a new one, it turns out that it only has DVI ports. In this case, you need to purchase an adapter and install it on the DVI connector:

Pay attention to the type of adapter. The fact is that the DVI connectors are different - new expensive video cards have DVI-D or DVI-I ports. The adapters are not interchangeable, check this point with the seller.

In this case, you will not need to buy a new monitor. New monitors also come with two types of connectors - VGA and DVI.

HDMI port. Where would we be without him in the 21st century? The multimedia interface is designed to transmit high-definition video and audio with copy protection. At the same time, it replaces both the above video and some audio ports (SCART, VGA, YPbPr, RCA, S-Video.). Probably this interface will eventually replace everything else. It can be found on any digital equipment - from a camera to a computer (or laptop).

The size is comparable to a USB port, and the data transfer speed is enormous compared to those listed above - up to 48 Gbps. Data transmission is carried out via a cable with good interference protection. The cable can be connected to a laptop and to a TV and watch videos. The cable length should not exceed 10 meters, otherwise a signal amplifier/repeater is needed.

About audio connectors I won't go into detail. Everything looks about the same as on a home DVD player, if we are talking about something special. An example of this is the SPDiF connector, which could be installed on an expansion slot:

Audio standard from SONY and PHILIPS, this card is connected to the motherboard using a connector to the corresponding connector. Standard jacks for connecting a microphone, speakers, and headphones look like this:

If you want HD audio, you may have to connect the appropriate adapter here. Read the documentation for your motherboard:

Network ports. There is no way we can do without them these days. We receive the Internet through a network interface via cable or radio. Motherboards have a standard built-in connector RJ 45 to connect the internet cable:

On old computers the speed standard was 100 Mbit/s, modern network cards provide 1000 Mbit/s. If one network card is not enough for you, you can buy an additional one and insert it into the expansion slot:

This card is suitable for a PCI slot. There are smaller options for PCI-express:

Check the data transfer speed of a particular card when purchasing. For fans of wireless networks, there is also a wide selection of Wi-Fi adapters:

They can also be connected to PCI or PCI - express expansion slots. However, if you don’t want to tinker with the system unit, you can also buy a USB version of this card:

You insert it into the port and enter the WIFI password. And you have another peripheral device connected. Many home printer models also have a WIi-Fi adapter, and with this setup you can print wirelessly. Fortunately, today there is a wide choice of network cards and printers.

How to disable USB ports when turning off the computer?

Finally, I’ll tell you how to solve one problem. I have a headset with a microphone for recording video and chatting on Skype. The Chinese have fallen in love with shoving LEDs wherever they need them for beauty. When the computer turns off, the backlight still remains on, since it is powered through the USB port.

The keyboard also glows, which is not entirely convenient at night, although not bad (if you type in the dark). In order to turn off power to the ports permanently, try typing the keyboard shortcut Win+R and in the “Run” line paste the command powercfg /h off.

After which you need to turn off the computer. The symptoms will likely go away. This command disables sleep mode and the computer shuts down completely. You can look at the power settings in the “Power Plan” in the control panel. But, there are board models where this setting is disabled through the BIOS. But on the most advanced ones this function is not disabled or is hidden very deeply. This is supposed to be convenient for charging gadgets at night.

In difficult cases, the motherboard documentation can help. Find the required jumper (jumper) and manually turn off the power. But it's too difficult. And the easiest way is to buy a USB hub with switches and connect the necessary peripherals to it. And don't suffer. Bye, see you again!

THR - transmitter intermediate data register(write only) Data written to the register will be transferred to the output shift register (when it is free), from which it will be output when the enable signal is present CTS. Bit 0 is transmitted (and received) first. If the sending length is less than 8 bits, the most significant bits are ignored.
RBR - receive data buffer register(read only) Data received by the input shift register is placed in the register RBR, from where they can be read by the processor. If by the time the next character is received, the previous one has not been read from the register, an overflow error is recorded. When the sending length is less than 8 bits, the most significant bits in the register have a zero value.
DLL - frequency divider low byte register.
DLM - frequency divider high byte register. The divisor is determined by the formula D=115200/V, where V is the transmission speed, bit/s. The input clock frequency of 1.8432 MHz is divided by a given factor to produce 16 times the data rate.
IER - interrupt enable register. A bit value of one enables an interrupt from the corresponding source.
Register bit assignments IER:
* bits =0 - not used;
* bit 3 - Mod_IE- by changing the state of the modem (any of the lines CTS, DSR, RI, DCD);
* bit 2 - RxL_IE- due to line break/error;
* bit 1 - TxD_IE- upon completion of the transfer;
* bit 0 - RxD_IE- upon receipt of a character (in FIFO mode - timeout interruption).
IIR - interrupt identification register and FIFO mode sign(only for reading). To simplify software analysis, UART organizes internal interrupt requests according to a four-level priority system. Priority order (descending): line status, character reception, transmitter register release, modem status. When interrupt conditions occur, the UART points to the highest priority source until it is cleared by the corresponding operation. Only after this a request will be issued indicating the next source. The purpose of the register bits is described below: IIR.
* Bits - a sign of FIFO mode:
11-mode FIFO 16550A;
10 - FIFO 16550 mode;
00 - normal.
* Bits - not used.
* Bit 3 - receive timeout interrupt in FIFO mode (there are characters to be read in the buffer).
* Bits - the reason for the interruption with the highest priority (in normal, not FIFO mode):
11 - error/line break, reset is performed by reading the line status register;
10 - character received, reset is performed by reading data;
01 - character transmitted (register THR empty), reset is performed by writing data;
00 - modem state change; Reset is performed by reading the modem status register.
* Bit 0 is a sign of an unserviced interrupt request (1 - no request, 0 - there is a request).
In FIFO mode, the cause of the interrupt is identified by the bits.
* O11 - error/line break. Reset is performed by reading the line status register.
* 010 - character accepted. Reset is performed by reading the receiver data register
* 110 - timeout indicator (in a 4-fold character time interval, not a single character was transmitted or received, although there is at least one in the buffer). Reset is performed by reading the receiver data register.
* 001 - register THR empty Reset is performed by writing data.
* 000 - modem state change ( CIS, DSR, RI or DCD). Reset is performed by reading the register MSR.
FCR - FIFO control register(for recording only). The purpose of the register bits is described below: FCR:
* Bits - ITL(Interrupt Trigger Level) - FIFO buffer fill level at which an interrupt is generated:
00 - 1 byte (default);
01 - 4 bytes;
10 - 8 bytes;
11 - 14 bytes.
*Bits are reserved.
* Bit 3 - enable DMA operations.
* Bit 2 - RESETTF(Reset Transmitter FIFO) - reset the FIFO transmitter counter (by writing one; the shift register is not reset).
* Bit 1 - RESETRF(Reset Receiver FIFO) - reset the FIFO receiver counter (by writing one; the shift register is not reset).
* Bit 0 - TRIFFOE(Transmit And Receive FIFO Enable) - enable (by unit) FIFO mode for the transmitter and receiver. When changing mode, FIFO buffers are automatically cleared.
LCR - line control register(channel parameter settings). The purpose of the register bits is described below: LCR.
* Bit 7 - DLAB(Divisor Latch Access Bit) - controls access to the frequency divider.
* Bit 6 - BRCON(Break Control) - generating a line break (sending zeros) when BRCON=1.
* Bit 5 - STICPAR(Sticky Parity) - forced formation of a parity bit:
0 - control bit is generated in accordance with the parity of the output symbol;
1 - constant value of the control bit: when EVENPAR=1 - zero, with EVENPAR=0 - single.
* Bit 4 - EVENPAR(Even Parity Select) - selection of control type: 0 - odd, 1 - even.
* Bit 3 - PAREN(Parity Enable) - control bit resolution:
1 - control bit (parity or constant) is enabled;
0 - control bit disabled.
* Bit 2 - STOPB(Stop Bits) - number of stop bits:
0 - 1 stop bit;
1 - 2 stop bits (for a 5-bit code, a stop bit will be 1.5 bits long).
* Bits - SERIALDB(Serial Data Bits) - number of data bits:
00 - 5 bits;
01-6 bits;
10 - 7 bits;
11 - 8 bits.
MCR - modem control register. The purpose of the register bits is described below: MCR.
* Bits =0 - reserved.
* Bit 4 - LME(Loopback Mode Enable) - enable diagnostic mode:
0 - normal mode;
1 - diagnostic mode (see below).
* Bit 3 - I.E.(Interrupt Enable) - enabling interrupts using an external output OUT2 MSR.7:
0 - interrupts are disabled;
1 - interrupts are enabled.
* Bit 2 - OUT1C(OUT1 Bit Control) - control of output signal 1 (not used); in diagnostic mode it enters the input MSR.6.
* Bit 1 - RTSC(Request To Send Control) - output control RTS; in diagnostic mode it enters the input MSR.4:
0 - active (-V);
1 - passive (+V).
* Bit 0 - DTRC(Data Terminal Ready Control) - output control DTR; in diagnostic mode it enters the input MSR.5:
0 - active (-V);
1 - passive (+V).
LSR - line status register(more precisely, the state of the transceiver). The purpose of the LSR register bits is described below.
* Bit 7 - FIFOE(FIFO Error Status) - error in received data in FIFO mode (the buffer contains at least one character received with a format error, parity error, or a break). In non-FIFO mode it is always 0.
* Bit 6 - TEMPT(Transmitter Empty Status) - the transmitter register is empty (there is no data to transmit in either the shift register or buffer registers THR or FIFO).
* Bit 5 - THRE(Transmitter Holding Register Empty) - the transmitter register is ready to receive a byte for transmission. In FIFO mode, indicates that there are no characters in the FIFO transmit buffer. May be a source of interruption.
* Bit 4 - BD(Break Detected) - line break indicator (the receiver input is in state 0 for no less than the time the symbol was sent).
* Bit 3 - F.E.(Framing Error) - frame error (incorrect stop bit).
* Bit 2 - RE(Parity Error) - check bit error (parity or fixed).
* Bit 1 - OE(Overrun Error) - overflow (loss of character). If the next character is received before the previous one is loaded from the shift register into the buffer register or into the FIFO register, the previous character in the shift register is lost.
* Bit 0 - D.R.(Receiver Data Ready) - received data is ready (in DHR or FIFO buffer). Reset - by reading the receiver.
Error indicators - bits - are reset after reading the register LSR. In FIFO mode, error flags are stored in the FIFO buffer along with each character. In the register, they are set (and cause an interrupt) at the moment when the character received in error is at the top of the FIFO (first in queue to be read). In the event of a line break, only one “break” character is entered into the FIFO, and the UART waits for recovery and the subsequent start bit. MSR- modem status register. The purpose of the register bits is described below: MSR:
* Bit 7 - DCD(Data Carrier Detect) - line status DCD:
0 - active (-V);
1 - passive (+V).
* Bit 6 - R.I.(Ring Indicator) - line status R.I.:
0 - active (-V);
1 - passive (+V).
* Bit 5 - DSR(Data Set Ready) - line status DSR:
0 - active (-V);
1 - passive (+V).
* Bit 4 - CTS(Clear To Send) - line status CTS:
0 - active (-V);
1 - passive (+V).
* Bit 3 - DDCD(Delta Data Carrier Detect) - state change DCD.
* Bit 2 - TERI(Trailing Edge Of Ring Indicator) - decay of the envelope R.I.(end call).
* Bit 1 - DDSR(Delta Data Set Ready) - state change DSR.
* Bit 0 - DCTS(Delta Clear To Send) - state change CTS.
Signs of change (bits) are reset when the register is read.
SRC - working register(8 bits), does not affect the operation of the UART, is intended for temporary data storage (not available in 8250).
IN diagnostic mode(at LME=1) an internal “stub” is organized inside the UART:
* the transmitter output is switched to a logical one state;
* receiver input is disabled; * inputs DSR, CTS, RI And DCD disconnected from input lines and internally controlled by bits DTRC, RTSC, OUT1C, IE;
* modem control outputs are switched to a passive state (logical zero).
Transmitted data in serial form is immediately received, which allows you to check the internal data channel of the port (including shift registers) and interrupt processing, as well as determine the speed of the UART.

The parallel port provides fairly high transfer speeds because the transfer is done one byte at a time. At the same time, when the cable is long or when data exchange is not very intensive, a serial port is more convenient.

The Serial Port transmits only 1 bit of data in one direction at a time. Data can be transferred through this port both from the computer to an external device and vice versa.

Computer serial ports usually comply with the international reference standard RS-232C (Reference Standard 232 version C), therefore any device that is also oriented to this standard can be connected to this port (for example, a mouse, modem, serial printer or serial port another computer). This interface uses 9 communication channels: one of them is used to transmit data from the computer, the other is used to receive data from a peripheral device. The remaining 7 channels are used to control the data exchange process.

The serial port consists of a UART (Universal Asynchronous Receiver/Transmitter) chip and auxiliary components. The UART chip receives bytes of data from the computer bus (in which they are transmitted in parallel), converts them into a sequence of bits, adds service bits and then performs the data transfer, and also performs the reverse steps of receiving the sequence of bits and converting the code from serial to parallel.

Modern UART chips are equipped with buffer memory and provide data transfer rates of up to 115 Kbps. New high-speed versions of the serial port - improved serial port ESP (Enhanced Serial Port) and Super ESP (Super Enhanced Serial Port) provide data transfer up to 460 Kbps.

During serial transmission, data is separated by service bits, such as a start bit and a stop bit. These bits indicate the start and end of the transmission of successive data bits. This transmission method allows synchronization between the receiving and transmitting sides, as well as equalizing the data exchange rate.

To identify and recognize errors during serial transmission, a parity bit may additionally be included in the send. The value of the parity bit is determined by the binary sum of all transmitted data bits. In Even Parity mode, the value of the parity bit is 0 if the sum of the bits is even, and 1 otherwise. Parity bits have inverse (reverse) values ​​(1 or 0, respectively) if the parity bit is odd (Odd Parity).

The standard configuration of the computer contains two serial ports. The difference between a serial port connector and a parallel one is that this connector has 9 pins, not sockets (maternal connector) (Fig. 1.3.11a). On the cable side of the connected device, the “mother” connector is used (Fig. 1.3.11b). The length of the serial port cable is limited to 18 m. The main devices connected to the serial port are old models of modems and mice.

Some computers, especially those oriented toward communications applications, may have serial ports that follow different standards (for example, RS-449A or RS-613) and have higher data transfer rates over longer distances.

Rice. 1.3.11. Serial port: a) 9-pin computer connector;

b) adapter cable serial port-USB

1.3.2.3.13. PS/2 port

The PS/2 (6-pin) port is so named because it first appeared on IBM PS/2 series computers. Of the 6 contacts, 4 contacts are used, one of which is intended for data transmission, the second for clock frequency signals (in the range of 10-16.7 kHz), the third contact is supplied with power (+5V), and the fourth is ground. Data transfer is similar to the serial port, but one acknowledgment bit is added when transferring data to the device. Modern computers have two PS/2 ports designed to connect a mouse (green connector) and a keyboard (purple connector) (Fig. 1.3.12a), but these devices are switching to using a USB port. The cable connectors for PS/2 devices (mouse and keyboard) are shown in Fig. 1.3.12b.

Rice. 1.3.12. PS/2 port: a) computer port sockets; b) cable plugs

Serial port - concept and types. Classification and features of the "Serial Port" category 2017, 2018.