{{Short description|Communication interface transmitting information sequentially}} {{Use American English|date=April 2022}} [[File:Serielle schnittstelle.jpg|thumb|A [[gender of connectors and fasteners|male]] [[DE-9]] connector on an [[IBM PC compatible]] computer (with serial port symbol) used for an [[RS-232]] serial port]] [[File:RS-232.jpeg|thumb|A female DE-9 connector on an RS-232 cable.]]

A '''serial port''' is a [[serial communication]] [[Interface (computing)|interface]] through which information transfers in or out sequentially one [[bit]] at a time.<ref>{{cite dictionary |dictionary=Webopedia |url=https://www.webopedia.com/definitions/serial-port/ |title=Serial Port Definition & Meaning |first=Vangie |last=Beal |date=September 1996 |access-date=2021-03-08 }}</ref> This is in contrast to a [[parallel port]], which communicates multiple bits simultaneously in [[Parallel communication|parallel]]. Throughout most of the [[history of personal computers]], data has been transferred through serial ports to devices such as [[modem]]s, [[computer terminal|terminal]]s, various [[peripheral]]s, and directly between computers.

While interfaces such as [[Ethernet]], [[FireWire]], and [[USB]] also send data as a serial [[Stream (computing)|stream]], the term ''serial port'' usually denotes [[Computer hardware|hardware]] compliant with [[RS-232]] or a related standard, such as [[RS-485]] or [[RS-422]].

Modern consumer [[personal computer]]s (PCs) have largely replaced serial ports with higher-speed standards, primarily USB. However, serial ports are still frequently used in applications demanding simple, low-speed interfaces, such as industrial automation systems, scientific instruments, [[point of sale]] systems and some industrial and consumer products.

[[Server (computing)|Server]] computers may use a serial port as a control console for diagnostics, while [[networking hardware]] (such as [[Router (computing)|router]]s and [[Network switch|switch]]es) commonly use serial console ports for configuration, diagnostics, and emergency maintenance access. To interface with these and other devices, [[USB-to-serial adapter]]s can quickly and easily add a serial port to a modern PC.

==Hardware== {{More citations needed section|date=November 2021}}

Modern devices use an [[integrated circuit]] called a [[UART]] to implement a serial port. This IC converts characters to and from [[asynchronous serial]] form, implementing the timing and framing of data specified by the serial protocol in hardware. The IBM PC implements its serial ports, when present, with one or more UARTs.

Very low-cost systems, such as some early [[home computer]]s, would instead use the [[CPU]] to send the data through an [[input/output|output]] pin, using the [[bit banging]] technique. These early home computers often had proprietary serial ports with pinouts and voltage levels incompatible with RS-232.

Before [[large-scale integration]] (LSI) made UARTs common, serial ports were commonly used in [[mainframe]]s and [[minicomputer]]s, which would have multiple small-scale integrated circuits to implement shift registers, logic gates, counters, and all the other logic needed. As PCs evolved, serial ports were included in the [[Super I/O]] chip and then in the [[chipset]].

{{Gallery | IBM PC Serial Card.jpg | An [[IBM PC]] serial card with a 25-pin connector (obsolete 8-bit [[Industry Standard Architecture|ISA]] card) | RS232 PCI-E.jpg | A [[PCI Express]]&nbsp;×1 card with one serial port | Four-port serial card with an octopus cable.jpg | A four-port serial (RS-232) PCI Express&nbsp;×1 [[expansion card]] with an [[octopus cable]] that breaks the card's DC-37 connector into four standard DE-9 connectors | FTDI USB SERIAL.jpg | A converter from USB to an RS-232 compatible serial port—more than a physical transition, it requires a driver in the host system software and a built-in processor to emulate the functions of the [[IBM XT]] compatible serial port hardware. |UART to USB adapter.jpg|UART to USB adapter }}

===DTE and DCE=== The individual signals on a serial port are unidirectional and when connecting two devices, the outputs of one device must be connected to the inputs of the other. Devices are divided into two categories: ''[[data terminal equipment]]'' (DTE) and ''[[data circuit-terminating equipment]]'' (DCE). A line that is an output on a DTE device is an input on a DCE device and vice versa, so a DCE device can be connected to a DTE device with a straight-wired cable, in which each pin on one end goes to the same numbered pin on the other end.

Conventionally, computers and terminals are DTE, while peripherals such as [[modem]]s are DCE. If it is necessary to connect two DTE (or DCE) devices together, a cable with reversed TX and RX lines, known as a [[Crossover cable|cross-over]], roll-over or [[null modem]] cable must be used.

===Gender=== Generally, serial port connectors are [[Gender of connectors and fasteners|gendered]], only allowing connectors to mate with a connector of the opposite gender. With [[D-subminiature]] connectors, the male connectors have protruding pins and female connectors have corresponding round sockets.<ref>{{cite web |url=http://www.cisco.com/c/en/us/support/docs/routers/7200-series-routers/12219-17.html |title=Serial Cable Connection Guide |date=2006-08-01 |publisher=CISCO |access-date=2016-01-31}}</ref> Either type of connector can be mounted on equipment or a panel; or terminate a cable.

Connectors mounted on DTE are likely to be male, and those mounted on DCE are likely to be female (with the cable connectors being the opposite). However, this is far from universal; for instance, most serial printers have a female DB25 connector, but they are DTEs.<ref>{{cite web |url=http://ltxfaq.custhelp.com/app/answers/detail/a_id/1216/~/rs232---dte-and-dce-connectors |title=RS232 - DTE and DCE connectors |date=2006-03-29 |publisher=Lantronix |access-date=2016-01-31 |archive-url=https://web.archive.org/web/20151214054632/http://ltxfaq.custhelp.com/app/answers/detail/a_id/1216/~/rs232---dte-and-dce-connectors |archive-date=2015-12-14 |url-status=dead }}</ref> In this circumstance, the appropriately gendered connectors on the cable or a [[gender changer]] can be used to correct the mismatch.

===Connectors=== The only connector specified in the original RS-232 standard was the 25-pin D-subminiature; however, many other connectors have been used to save money or save on physical space, among other reasons. In particular, since many devices do not use all of the 20 signals that are defined by the standard, connectors with fewer pins are often used. While specific examples follow, countless other connectors have been used for RS-232 connections.

The 9-pin [[D-subminiature|DE-9]] connector has been used by most IBM-compatible PCs since the Serial/Parallel Adapter option for the [[PC-AT]], where the 9-pin connector allowed a serial and parallel port to fit on the same card.<ref>{{Cite web|title=IBM PC AT Serial/Parallel Adapter|url=http://www.minuszerodegrees.net/oa/OA%20-%20IBM%20PC%20AT%20Serial_Parallel%20Adapter.pdf|url-status=dead|archive-url=https://web.archive.org/web/20200224102106/http://minuszerodegrees.net/oa/OA%20-%20IBM%20PC%20AT%20Serial_Parallel%20Adapter.pdf|archive-date=2020-02-24}}</ref> This connector has been standardized for RS-232 as [[TIA-574]].

Some miniaturized electronics, particularly [[graphing calculator]]s<ref>{{Cite web|title=TI-73...92+/V200 TI Link Guide|url=http://merthsoft.com/linkguide/cable.html|access-date=2020-08-14|website=merthsoft.com}}</ref> and hand-held [[Amateur radio|amateur]] and [[two-way radio]] equipment,<ref>{{Cite web|title=Technical Section |url=https://www.miklor.com/COM/UV_Technical.php#progcable|access-date=2020-08-14|website=Miklor.com}}</ref> have serial ports using a [[phone connector (audio)|phone connector]], usually the smaller 2.5 or 3.5&nbsp;mm connectors and the most basic 3-wire interface—transmit, receive and ground.

[[8P8C]] connectors are also used in many devices. The [[EIA/TIA-561]] standard defines a pinout using this connector, while the [[rollover cable]] (or Yost standard) is commonly used on [[Unix]] computers and network devices, such as equipment from [[Cisco Systems]].<ref>{{Cite web|title=Cabling Guide for Console and AUX Ports|url=https://www.cisco.com/c/en/us/support/docs/routers/7000-series-routers/12223-14.html|access-date=2020-08-14|website=Cisco }}</ref>

Many models of [[Macintosh]] favor the related RS-422 standard, mostly using circular [[mini-DIN connector]]s. The Macintosh included a standard set of two ports for connection to a printer and a modem, but some [[PowerBook]] laptops had only one combined port to save space.<ref>{{Cite web |title=Classic Mac Ports |url=https://whitefiles.org/tec/pgs/h10b.htm |access-date=2020-08-14 |website=WhiteFiles.org }}</ref>

[[10P10C]] connectors can be found on some devices.<ref name="National Instruments 2013">{{cite web |url=http://www.ni.com/pdf/manuals/371253e.pdf |publisher=National Instruments |title=Serial Quick Reference Guide |website=NI.com |date=July 2013 |access-date=2021-06-18 }}</ref>

Another common connector is a {{resx|10|2}} [[pin header]] common on motherboards and add-in cards which is usually converted via a [[ribbon cable]] to the more standard 9-pin DE-9 connector (and frequently mounted on a free slot plate or other part of the housing).<ref>{{Cite book |url=https://www.intel.com/content/dam/support/us/en/documents/motherboards/server/s5000pal/sb/s5000pal_s5000xal_tps_r2_0.pdf |title=Intel Server Board S5000PAL/S5000XAL Technical Product Specification |pages=38 }}</ref>

{{Gallery | CiscoConsoleCable.jpg | A Cisco rollover cable using the 8P8C Yost standard. | Mac lc printer modem ports.jpg|Pair of female [[Mini DIN-8]] connectors used for [[RS-422]] serial ports on a [[Macintosh LC]] computer. | CAN Connecteur.svg|Pin numbering looking into a<br/>male [[D-subminiature|DE-9]] connector. | DE-9 Female.svg|Pin numbering looking into a<br/>female DE-9 connector. }}

===Pinouts=== {{See also|RS-232#Data and control signals}} {| class="wikitable sortable" style="margin:auto; text-align:center;" |+Pin assignments of common RS-232 signals<ref>{{cite web |url=http://www.hardwarebook.info/Serial_(PC_9) |title=Serial (PC 9) |author-first=Joakim |author-last=Ögren |access-date=2010-07-07 |archive-url=https://web.archive.org/web/20100811173526/http://www.hardwarebook.info/Serial_%28PC_9%29 |archive-date=2010-08-11 }}</ref> ! colspan="4" |Signal !! colspan="11" |Connector pin |- ! rowspan="2" |Name !! rowspan="2" |[[ITU-T V.24|V.24]] circuit !! rowspan="2" |{{soft hyphen|Abbrev|iation}} !! rowspan="2" |Origin !! rowspan="2" |{{nowrap|[[DB-25]]}} !! rowspan="2" |{{nowrap|[[DE-9]]}} {{nowrap|([[TIA-574]])}} !! rowspan="2" |[[Modified Modular Jack|MMJ]] !! colspan="5" |[[8P8C]] ("RJ45") !! colspan="3" |[[10P10C]] ("RJ50") {{efn|A 10P10C socket can accept a 8P8C plug. In that case, pins 1-8 on the 8P8C plug connect to pins 2-9 in the 10P10C socket.}} |- ! [[EIA/TIA-561]] !! Yost (DTE)<ref name="Yost">{{cite web |url=http://yost.com/computers/RJ45-serial/ |title=Yost Serial Device Wiring Standard |access-date=2020-05-10 |archive-url=https://web.archive.org/web/20200617132523/http://yost.com/computers/RJ45-serial/ |archive-date=2020-06-17 |url-status=dead }}</ref> !! Yost (DCE)<ref name="Yost" /> !! Cyclades !! [[Digi International|Digi]] (ALTPIN option) !! [[National Instruments|National {{soft hyphen|Instru|ments}}]]<ref name="National Instruments 2013">{{cite web |url=http://www.ni.com/pdf/manuals/371253e.pdf |publisher=National Instruments |title=Serial Quick Reference Guide |website=NI.com |date=July 2013 |access-date=2021-06-18 }}</ref> !! {{soft hyphen|Cy|clades}} !! Digi |- | Transmitted Data || 103 || TxD | [[Data terminal equipment|DTE]] || 2 || 3 || 2 || 6 || 6 || 3 || 3 || 4 || 8 || 4 || 5 |- | Received Data || 104 || RxD | [[Data circuit-terminating equipment|DCE]] || 3 || 2 || 5 || 5 || 3 || 6 || 6 || 5 || 9 || 7 || 6 |- | Data Terminal Ready || 108/2 || DTR | DTE || 20 || 4 || 1 || 3 || 7 || 2 || 2 || 8 || 7 || 3 || 9 |- | Data Carrier Detect || 109 || DCD | DCE || 8 || 1 || {{n/a}} || 2 || rowspan="2" |2 {{efn|The Yost standard combines DSR and DCD. Only one signal may be connected at the DCE end. When using a crossover cable to connect two DTE devices ([[null modem]]) this signal connects to DTR on the other device.}} || 7 || 7 || 1 || 10 || 8 || 10 |- | Data Set Ready|| 107 || DSR | DCE || 6 || 6 || 6 || rowspan="2" |1 {{efn|EIA/TIA 561 combines DSR and RI,<ref>{{cite web| url = http://www.hardwarebook.info/RS-232D| title = Hardware Book RS-232D}}</ref><ref>{{cite web| url = http://www.t0rchthe.net/rj45console/index.html| title = RS-232D EIA/TIA-561 RJ45 Pinout}}</ref>. Only one signal may be connected at the DCE end. When connecting two DTE devices ([[null modem]]) RI is not used and this signal should be connected to DTR on the other device in parallel with pin 2 (DCD), or, if that is not possible, left unconnected.}} || {{n/a}} || 8 || {{n/a}} || 5 || 9 || 2 |- | Ring Indicator || 125 || RI | DCE || 22 || 9 || {{n/a}} || {{n/a}} || {{n/a}} || {{n/a}} || {{n/a}} || 2 || 10 || 1 |- | Request To Send {{efn|name=rtr|1=The ''Request To Send'' (RTS, V.24 circuit 105) signal pins are, in fact, nearly always used to carry the ''Ready To Receive'' (RTR, V.24 circuit 133) signal, but even when used for this purpose is still universally referred to as ''RTS'' in documentation.}} || 105 (133) {{efn|name=rtr}} || RTS {{efn|name=rtr}} | DTE || 4 || 7 || {{n/a}} || 8 || 8 || 1 || 1 || 2 || 4 || 2 || 3 |- | Clear To Send || 106 || CTS | DCE || 5 || 8 || {{n/a}} || 7 || 1 || 8 || 5 || 7 || 3 || 6 || 8 |- | Signal Ground {{efn|''Signal Ground'' (G) is a [[Single-ended signaling|common return]] for the other connections.}}|| 102 || G | {{n/a}} || 7 || 5 || 3, 4 {{efn|name=gg|''Signal Ground'' (G) appears on two pins in some connectors but carry the same signal; the two pins should be connected in parallel at both ends (if possible) to provide a lower impedance connection.}} || 4 || 4, 5 {{efn|name=gg}} || 4, 5 {{efn|name=gg}}|| 4 || 6 || 6 || 5 || 7 |- | Protective Ground {{efn|''Protective Ground'' (PG), when available, is intended to be connected by each device to its own frame ground or similar for electrical safety. Connecting Protective Ground to Signal Ground is a common practice but not recommended.}} || 101 || PG | {{n/a}} || 1 || {{n/a}} || {{n/a}} || {{n/a}} || {{n/a}} || {{n/a}} || {{n/a}} || 3 || {{n/a}} || 1 || 4 |}

{{notelist}}

===Hardware abstraction=== Operating systems usually create symbolic names for the serial ports of a computer, rather than requiring programs to refer to them by hardware address.

[[Unix-like]] operating systems usually label the serial port devices {{mono|/dev/tty*}}. ''TTY'' is a common trademark-free abbreviation for ''[[teletype]]'', a device commonly attached to early computers' serial ports, and {{mono|*}} represents a string identifying the specific port; the syntax of that string depends on the operating system and the device.

On [[Linux]], serial ports intended for general communication have names that start with {{mono|/dev/tty}} followed by a type prefix consisting of capital letters and ending with a sequence number starting with {{mono|0}}. For example, [[8250]]/[[16550 UART]] serial ports are named {{mono|/dev/ttyS*}} ({{mono|/dev/ttyS0}}, {{mono|/dev/ttyS1}}, ...etc); USB adapters appear as {{mono|/dev/ttyUSB*}}, {{mono|/dev/ttyACM*}}, or {{mono|/dev/ttyHS*}}; other types have yet other prefixes. Some virtual serial ports not intended for general communication have names that intentionally do not match this pattern.

The [[DOS]] and [[Windows]] environments refer to serial ports as [[COM (hardware interface)|COM]] ports and are named {{mono|COM}} followed by a sequence number beginning with {{mono|1}}: {{mono|COM1}}, {{mono|COM2}}, ..etc.<ref>{{cite news |title=What Is a Com1 Port? |url=https://www.techwalla.com/articles/what-is-a-com1-port |author=Stephen Byron Cooper |newspaper=Techwalla |access-date=2021-09-30}}</ref>

==Common applications== This list includes some of the more common devices that are connected to the serial port on a PC. Some of these, such as modems and serial mice, are falling into disuse, while others are readily available. Serial ports are very common on most types of [[microcontroller]], where they can be used to communicate with a PC or other serial devices.

{{Div col|colwidth=30em}} * Dial-up [[modem]]s * Configuration and management of [[Computer network|networking]] equipment such as [[Router (computing)|routers]], [[Network switch|switches]], [[Firewall (computing)|firewalls]], [[load balancer]]s * [[GPS]] receivers (typically [[NMEA 0183]] at {{nowrap|4,800 bit/s}}) * [[Bar code scanner]]s and other [[point of sale]] devices * [[LED]] and [[LCD]] text displays * [[Satellite phone]]s, low-speed satellite modems and other satellite-based transceiver devices * [[Flat-panel display]]s to control screen functions by external computer, other AV components or remotes * Test and measuring equipment such as digital [[multimeter]]s and weighing systems * Updating [[firmware]] on various consumer devices * [[CNC controller]]s * [[Uninterruptible power supply]] management and status reporting * Stenography or [[Stenotype]] machines * Software debuggers that run on a second computer * Console or debugger interface to [[Microprocessor development board|microprocessor development or evaluation board]]s * Industrial field buses * [[Printer (computing)|Printer]]s * [[Computer terminal]], [[teletype]] * [[Computer network|Networking]] (Macintosh [[AppleTalk]] using RS-422 at {{nowrap|230.4 kbit/s}}) * Serial mouse {{Div col end}}

Since the control signals for a serial port can be driven by any [[digital signal]], some applications used the control lines of a serial port to monitor external devices, without exchanging serial data. A common commercial application of this principle was for some models of [[uninterruptible power supply]] which used the control lines to signal loss of power, low battery, and other status information. At least some [[Morse code]] training software used a code key connected to the serial port to simulate actual code use; the status bits of the serial port could be sampled very rapidly and at predictable times, making it possible for the software to decipher Morse code.

Serial computer mice and low-power data converters (e.g. RS-232 to 422 converters) may draw their operating power from the received data or control signals.<ref>{{cite web |last1=Chan |first1=Alvin |title=AN-681 PC Mouse Implementation Using COP800 |url=https://www.ti.com/lit/an/snaa005/snaa005.pdf |publisher=National Semiconductor |access-date=29 July 2023 |date=1990}}</ref><ref>{{cite web |title=AN519 Implementing a Simple Serial Mouse Controller |url=https://ww1.microchip.com/downloads/en/Appnotes/00519c.pdf |publisher=Microchip Technology Inc. |access-date=29 July 2023 |date=1997}}</ref>. This mode is also known as "self powered".

==Settings== {| class="wikitable floatright" style="width: 33%;" |+ Common serial port speeds ! style=max-width:5em | [[Bit rate]] {{nowrap|(bit/s)}} !! style=max-width:5em | Time per bit (μs) !! style=max-width:6em | [[Windows]] predefined serial port speed<ref>{{Cite web |title=_SERIAL_COMMPROP (ntddser.h) - Windows drivers {{!}} Microsoft Learn |url=https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_commprop |work=Windows Hardware Developer |publisher=[[Microsoft]] |date=2022-09-01 |access-date=2025-02-08}}</ref><ref name="winbase.h">{{cite web |title=DCB (winbase.h) - Windows apps {{!}} Microsoft Learn |url=https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb |work=Windows App Development |publisher=[[Microsoft]] |date=2021-04-01 |access-date=2025-02-08}}</ref> || Common applications |- | 75 || 13333.3 || {{yes}} || |- | 110 || 9090.9 || {{yes}} || [[Bell 101 modem]] |- | 134.5 || 7434.9 || {{yes}} || [[IBM 2741]] terminal |- | 150 || 6666.6 || {{yes}} || |- | 300 || 3333.3 || {{yes}} || [[Bell 103 modem]] or [[ITU-T V.21|V.21]] modem |- | 600 || 1666.7 || {{yes}} || |- | 1,200 || 833.3 || {{yes}} || [[Bell 202]], [[Bell 212A]], or [[ITU-T V.22|V.22]] modem |- | 1,800 || 555.6 || {{yes}} || |- | 2,400 || 416.7 || {{yes}} || [[V.22bis]] modem |- | 4,800 || 208.3 || {{yes}} || [[V.27ter]] modem |- | 7,200 || 138.9 || {{yes}} || |- | 9,600 || 104.2 || {{yes}} || [[ITU-T V.32|V.32]] modem |- | 14,400 || 69.4 || {{yes}} || [[V.32bis]] modem |- | 19,200 || 52.1 || {{yes}} || |- | 31,250 || 32 || {{no}} || [[MIDI]] port |- | 38,400 || 26.0 || {{yes}} || |- | 56,000 || 17.9 || {{yes}} || [[ITU-T V.90|V.90]]/[[V.92]] modem |- | 57,600 || 17.4 || {{yes}} || [[V.32bis]] modem with [[V.42bis]] compression |- | 76,800 || 13.0 || {{no}} || |- | 115,200 || 8.68 || {{yes}} || [[ITU-T V.34|V.34]] modem with [[V.42bis]] compression, low cost serial [[ITU-T V.90|V.90]]/[[V.92]] modem with [[V.42bis]] or [[ITU-T V.44|V.44]] compression |- | 125,000 || 8.00 || {{no}} || ISO 11898-3 [[CAN bus]] |- | 128,000 || 7.81 || {{yes}} || [[Basic Rate Interface]] [[ISDN]] [[terminal adapter]] |- | 230,400 || 4.34 || {{no}} || [[LocalTalk]], [[Econet]], high end serial [[ITU-T V.90|V.90]]/[[V.92]] modem with [[V.42bis]] or [[ITU-T V.44|V.44]] compression<ref>{{Cite web | url = https://www.multitech.com/documents/publications/data-sheets/86002093.pdf | title = MultiModem ZBA | publisher = Multi-Tech Systems, Inc | date = January 2019 | access-date = September 26, 2019 | archive-url = https://web.archive.org/web/20190303121617/https://www.multitech.com/documents/publications/data-sheets/86002093.pdf | archive-date = March 3, 2019 | url-status = dead }}</ref><ref>{{Cite web | url = https://unicom.usr.com/support/3453c/3453c-ug/control_data_rates.html | title = Courier 56K Business Modem: User Guide: Controlling Data Rates | publisher = [[USRobotics]] | date = 2007 | access-date = September 26, 2019 | archive-url = https://web.archive.org/web/20170804100605/http://unicom.usr.com/support/3453c/3453c-ug/control_data_rates.html | archive-date = August 4, 2017 | url-status = live }}</ref> |- | 250,000 || 4.0 || {{no}} || [[DMX512]], stage lighting and effects network |- | 256,000 || 3.91 || {{Yes}} || |}

Serial standards provide for many different operating speeds as well as adjustments to the protocol to account for different operating conditions. The most well-known options are speed, number of data bits per character, parity, and number of stop bits per character.

In modern serial ports using a UART integrated circuit, all these settings can be software-controlled. Hardware from the 1980s and earlier may require setting switches or jumpers on a circuit board.

The configuration for serial ports designed to be connected to a PC has become a de facto standard, usually stated as 9600/8-N-1.

===Speed=== Serial ports use two-level (binary) signaling, so the data rate in bits per second is equal to the symbol rate in [[baud]]. The total speed includes bits for framing (stop bits, parity, etc.) and so the effective data rate is lower than the bit transmission rate. For example, with 8-N-1 character framing, only 80% of the bits are available for data; for every eight bits of data, two more framing bits are sent.

A standard series of rates is based on multiples of the rates for electromechanical [[teleprinter]]s; some serial ports allow many arbitrary rates to be selected, but the speeds on both sides of the connection must match for data to be received correctly. Bit rates commonly supported include 75, 110, 300, 1200, 2400, 4800, 9600, 19,200, 38,400, 57,600 and {{nowrap|115,200 bit/s}}.<ref name="winbase.h"/> Many of these standard modem bit rates are multiples of either {{nowrap|1.2 kbit/s}} (e.g., 19200, 38400, 76800) or {{nowrap|0.9 kbit/s}} (e.g., 57600, 115200).<ref>{{cite web |url=https://cdn.hackaday.io/files/1614916909230944/SX1272_DS_V4.pdf |title=SX1272/73 - 860 MHz to 1020 MHz Low Power Long Range Transceiver Datasheet |publisher=[[Semtech]] |date=January 2019 }}</ref> [[Crystal oscillator]]s with a frequency of 1.843200&nbsp;MHz are sold specifically for this purpose. This is 16 times the fastest bit rate, and the serial port circuit can easily divide this down to lower frequencies as required.

The capability to set a bit rate does not imply that a working connection will result. Not all bit rates are possible with all serial ports. Some special-purpose protocols, such as [[MIDI]] for musical instrument control, use serial data rates other than the teleprinter standards. Some serial port implementations can automatically choose a bit rate by observing what a connected device is sending and synchronizing to it.

===Data bits=== The number of data bits in each character can be 5 (for [[Baudot code]]), 6 (rarely used), 7 (for true [[ASCII]]), 8 (for most kinds of data, as this size matches the size of a [[byte]]), or 9 (rarely used). 8 data bits are almost universally used in newer applications. 5 or 7 bits generally only make sense with older equipment, such as teleprinters.

Most serial communications designs send the data bits within each byte [[least significant bit]] first. Also possible, but rarely used, is [[most significant bit]] first; this was used, for example, by the [[IBM 2741]] printing terminal. The order of bits is not usually configurable within the serial port interface but is defined by the host system. To communicate with systems that require a different bit ordering than the local default, local software can re-order the bits within each byte just before sending and just after receiving.

===Parity=== {{Main|Parity bit}}

''Parity'' is a method of detecting errors in transmission. When parity is used with a serial port, an extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even. If a byte is received with the wrong number of 1s, then it must have been corrupted. Correct parity does not necessarily indicate absence of corruption as a corrupted transmission with an even number of errors will pass the parity check. A single parity bit does not allow implementation of [[error correction]] on each character, and [[communication protocol]]s working over serial data links will typically have higher-level mechanisms to ensure data validity and request retransmission of data that has been incorrectly received.

The parity bit in each character can be set to one of the following:

* '''None (N)''' means that no parity bit is sent and the transmission is shortened. * '''Odd (O)''' means that the parity bit is set so that the number of 1 bits is odd. * '''Even (E)''' means that the parity bit is set so that the number of 1 bits is even. * '''Mark (M)''' parity means that the parity bit is always set to the mark signal condition (1 bit value). * '''Space (S)''' parity always sends the parity bit in the space signal condition (0 bit value).

Aside from uncommon applications that use the last bit (usually the 9th) for some form of addressing or special signaling, mark or space parity is uncommon, as it adds no error detection information.

Odd parity is more useful than even parity since it ensures that at least one state transition occurs in each character, which makes it more reliable at detecting errors like those that could be caused by serial port speed mismatches. The most common parity setting, however, is ''none'', with error detection handled by a communication protocol.

To allow detection of messages damaged by [[line noise]], electromechanical teleprinters were arranged to print a special character when received data contained a parity error.

===Stop bits=== Stop bits sent at the end of every character allow the receiving signal hardware to detect the end of a character and to resynchronize with the character stream. Electronic devices usually use one stop bit. If slow electromechanical [[teleprinter]]s are used, one-and-one-half or two stop bits may be required.

===Conventional notation=== [[File:Puerto serie Rs232.png|frame|In this diagram, two [[byte]]s are sent, each consisting of a start bit, followed by eight data bits (bits 0-7), and one stop bit, for a 10-bit character frame in 8N1 format. The line on a diagram staying up indicates an excited ("mark" or 1) state of the line, low − unasserted ("space" or 0) state. Both up and low lines drawn for a bit (forming a square) indicate a data bit with value that can be either 0 or 1]] The data/parity/stop (D/P/S) conventional notation specifies the framing of a serial connection. The most common configuration for the [[Personal computer|personal computing devices]] is '''8-N-1''' (also spelled as 8N1, 8-None-1<ref name="modemhelp"/>), in which there is one start bit, eight ("8") data bits, no ("N") parity bit, and one ("1") stop bit.<ref>{{cite web |title=Definition of N-8-1 |url=https://www.pcmag.com/encyclopedia/term/n-8-1 |website=PCMAG |language=en}}</ref> In this notation, the parity bit is not included into the count of the data bits. For example, 7/E/1 (7E1) means that an even parity bit is added to the 7 data bits for a total of 8 bits between the start and stop bits.

The abbreviation is usually given together with the line speed in [[bits per second]], as in "9600–8-N-1". The speed (or [[baud rate]]) includes bits for [[Data frame|framing]] (stop bits, parity, etc.), thus the effective data rate is lower than the baud rate. For 8-N-1 encoding, only 80% of the bits are available for data (for every eight bits of data, ten bits are sent over the serial link&nbsp;&mdash; one start bit, the eight data bits, and the one stop bit).<ref name="modemhelp">{{cite web | url = http://www.modemhelp.net/faqs/8n1.shtml | title = What does 8-N-1 mean? | access-date = 2013-12-25 | publisher = modemhelp.net }}</ref>

===Flow control=== [[Flow control (data)|Flow control]] is used in circumstances where a transmitter might be able to send data faster than the receiver is able to process it. To cope with this, serial lines often incorporate a [[Handshake (computing)|handshaking]] method. There are ''hardware'' and ''software'' handshaking methods.

'''Hardware handshaking''' is done with extra signals, often the RS-232 RTS/CTS or DTR/DSR signal circuits. RTS and CTS are used to control data flow, signaling, for instance, when a buffer is almost full. Per the RS-232 standard and its successors, DTR and DSR are used to signal that equipment is present and powered up so are usually asserted at all times. However, non-standard implementations exist, for example, printers that use DTR as flow control.

'''Software handshaking''' is done for example with [[ASCII]] control characters [[XON/XOFF]] to control the flow of data. The XON and XOFF characters are sent by the receiver to the sender to control when the sender will send data; that is, these characters go in the opposite direction to the data being sent. The system starts in the ''sending allowed'' state. When the receiver's buffers approach capacity, the receiver sends the XOFF character to tell the sender to stop sending data. Later, after the receiver has emptied its buffers, it sends an XON character to tell the sender to resume transmission. It is an example of [[in-band signaling]], where control information is sent over the same channel as its data. The advantage of hardware handshaking is that it can be extremely fast, it works independently of imposed meaning, such as ASCII on the transferred data, and it is [[state (computer science)|stateless]]. Its disadvantage is that it requires more hardware and cabling, and both ends of the connection must support the hardware handshaking protocol used. The advantage of software handshaking is that it can be done with absent or incompatible hardware handshaking circuits and cabling. The disadvantage, common to all in-band control signaling, is that it introduces complexities in ensuring that control messages get through even when data messages are blocked, and data can never be mistaken for control signals. The former is normally dealt with by the operating system or device driver; the latter normally by ensuring that control codes are [[escape sequence|escaped]] (such as in the [[Kermit protocol]]) or omitted by design (such as in [[ANSI escape code|ANSI terminal control]]). If '''no handshaking''' is employed, an overrun receiver might simply fail to receive data from the transmitter. Approaches for preventing this include reducing the speed of the connection so that the receiver can always keep up, increasing the size of [[data buffer|buffers]] so it can keep up averaged over a longer time, using delays after time-consuming operations (e.g. in [[termcap]]) or employing a mechanism to resend data which has not been received correctly (e.g. [[Transmission Control Protocol|TCP]]).

==See also== * {{Section link|List of Bluetooth profiles|Serial Port Profile (SPP)}} * {{Annotated link|Serial cable}} * {{Annotated link|Serial over LAN}} * [[Teleprinter]]{{snd}}Device that motivated serial port development * {{Annotated link|Virtual COM port}}

==References== {{Reflist}}

==Further reading== * ''Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems''; 2nd Edition; Jan Axelson; Lakeview Research; 380 pages; 2007; {{ISBN|978-1-931-44806-2}}.

==External links== {{Wikibooks|Programming:Serial Data Communications}} * {{Commons category-inline}} * [https://pinoutguide.com/SerialPorts/ RS-232 and other serial port pinouts list]

{{Basic computer components}}

[[Category:Computer connectors]] [[Category:Legacy hardware]] [[Category:Out-of-band management]] [[Category:Serial buses]] [[Category:IBM PC compatibles]]