Universal Asynchronous Receiver-Transmitter (UART ) - a node of computing devices designed to communicate with other digital devices. Converts the transmitted data in a serial form so that it is possible to transfer them over one physical digital line to another similar device. The conversion method is well standardized and widely used in computer technology (especially in embedded devices and systems on a chip (SoC) ).
It is a logic circuitry, on the one hand connected to the bus of a computing device, and on the other having two or more pins for external connection.
UART can be a separate chip (for example, Intel I8251, I8250) or be part of a large integrated circuit (for example, a microcontroller). Used to transfer data through the serial port of a computer , often embedded in microcontrollers .
Content
Transmission and Reception Method
Data is transferred to UART one bit at regular intervals. This time period is determined by the specified UART speed and is indicated in bauds for a particular connection (which in this case corresponds to bits per second). There is a generally accepted number of standard speeds: 300; 600; 1200; 2400; 4800; 9600; 19,200; 38,400; 57600; 115200; 230400; 4,60800; 921600 baud Speed ( baud) and bit duration ( , seconds) are related by the relation . Baud rate is sometimes referred to as the slang word baud rate or bit rate .
In addition to information bits, UART automatically inserts synchronization labels, the so-called start and stop bits, into the stream. Upon receipt, these extra bits are removed from the stream. Usually the start and stop bits frame one byte of information (8 bits), while the least significant bit is transmitted first, immediately after the start. There are UART implementations that transmit 5, 6, 7, or 9 information bits. Framed by start and stop bits are the minimum premise. Some UART implementations use two stop bits in transmission to reduce the likelihood of a receiver and transmitter out of sync during heavy traffic. The receiver ignores the second stop bit, perceiving it as a short pause on the line.
It is agreed that the passive (in the absence of a data stream) state of the UART input and output is logical 1. The start bit is always logical 0, so the UART receiver waits for a 1 to 0 differential and counts from it a time interval of half the bit length (the middle of the start bit transmission ) If at this moment the input is still 0, then the process of receiving the minimum sending starts. To do this, the receiver counts 9 bit durations in a row (for 8-bit data) and at each moment captures the input state. The first 8 values are received data, the last value is a test (stop bit). The stop bit value is always 1. If the actual value is different, the UART will fix the error.
For the formation of time intervals, the transmitting and receiving UARTs have a source of accurate time (clocking). The accuracy of this source should be such that the sum of the errors (receiver and transmitter) of the installation of the time interval from the beginning of the start pulse to the middle of the stop pulse does not exceed half (or preferably at least a quarter) of the bit interval. [1] For an 8-bit transmission, this value is 0.5 / 9.5 ≈ 5%. In practice, taking into account possible signal distortions in the line, the total clock error should be no more than 3%. Since in the worst case, the error of the clocks of the receiver and the transmitter can be summed up, the recommended tolerance on the accuracy of the UART clock is not more than 1.5%.
Since the sync bits occupy part of the bitstream, the resulting UART bandwidth is less than the connection speed. For example, for 8-bit 8-N-1 format packets, the synchronization bits occupy 20% of the stream, which at a physical line speed of 115,200 baud means a useful data rate of 92,160 bps or 11,520 bytes / s.
Parity
data | number of single bits | parity bit | |
---|---|---|---|
even | odd | ||
0000000 | 0 | 0 | one |
1010001 | 3 | one | 0 |
1101001 | four | 0 | one |
1111111 | 7 | one | 0 |
Many UART implementations have the ability to automatically control data integrity using bit parity. When this function is enabled, the last data bit in the minimum burst (“parity bit”) is controlled by the UART logic and contains information on the parity of the number of unit bits in this minimum burst. Distinguish between parity control ( Eng. Even parity ), when the sum of the number of unit bits in the package is an even number , and odd control ( Eng. Odd parity ), when this amount is odd. Upon receipt of such a parcel, the UART can automatically control the parity bit and display the corresponding signs of correct or erroneous reception.
Short record of parameters
A short way to write UART parameters, such as the number of data bits, the presence and type of the parity bit, and the number of stop bits, was developed and adopted. It looks like a number-letter-number record, where:
- The first digit indicates the number of data bits, for example, 8.
- The letter indicates the presence and type of parity bit. There are N (No parity) - without a parity bit; E (Even parity) - with a parity check bit, O (Odd parity) - with an odd parity bit;
- The last digit indicates the duration of the stop bit. There are values 1, 1.5 and 2 for the duration of the stop bit in 1, 1.5 and 2 bit intervals, respectively.
For example, an 8-N-1 record indicates that the UART is set to 8 data bits without a parity bit and one stop bit. For completeness, this entry is provided with an indication of the speed of the UART, for example, 9600/8-N-1.
Break
Some UARTs have the ability to send and receive a special package called Break. It consists of a continuous zero state of a line with a duration that is obviously longer than the minimum burst, usually 1.5 minimum bursts (for 8N1 these are 15 bit intervals). Some communication protocols use this property, for example, the LIN protocol uses Break to indicate a new frame.
Flow control
Early UART devices could be so slow that they did not have time to process the stream of received data. To solve this problem, UART modules were sometimes provided with separate outputs and flow control inputs. When the input buffer was full, the logic of the receiving UART set the prohibition level at the corresponding output, and the transmitting UART suspended the transmission.
Later, flow control was assigned to communication protocols (for example, using the XOn / XOff method ), and the need for separate flow control lines gradually disappeared.
Physical layer
The UART logic circuit has inputs and outputs with logical levels corresponding to the semiconductor technology of the circuit: CMOS , TTL , etc. Such a physical level can be used within a single device, however, it is unsuitable for switched long connections due to low protection against electrical damage and interference . For such cases, special physical levels have been developed, such as current loop , RS-232 , RS-485 , LIN, and the like.
A specific variation of the physical layer of the asynchronous interface is the physical layer of IrDA .
There are physical UART layers for complex environments. In a sense, a standard computer telephone modem can also be called a specific physical layer of an asynchronous interface. There are special microchips for wired modems made specifically as the physical layer of an asynchronous interface (i.e. protocol transparent). A radio channel physical layer is also produced in the form of modules for radio receivers and radio transmitters.
Physical Layer Driver
To convert the logical inputs and outputs of UART into signals of the corresponding physical layer, special electronic circuits called drivers are used. For all popular physical layers, there are integrated drivers in the form of microcircuits.
Duplex
UART logic typically allows simultaneous transmission and reception. This ability is often indicated by the slang word duplex . However, not all physical layers can simultaneously transmit data in both directions. In such cases, it is customary to talk about half-duplex communication. There are also solutions in which data transfer is physically possible only in one direction, then we speak of simplex communication.
Network
Initially, UART was designed to connect two devices on a point-to-point basis. Subsequently, physical layers were created that allow you to connect more than two UARTs on the principle of "one speaks - several listen." Such physical layers are called network layers. There are implementations such as a common bus (when all transceivers are connected to one wire) and a ring (when receivers and transmitters are connected in pairs in a closed ring). The first option is simpler and more common. The second option is more complicated, but more reliable and faster: the operation of all nodes is guaranteed (the transmitting node will hear the echo of its message only if it is successfully relayed by all nodes); any node can start transmission at any time, without worrying about the risk of collision. The most famous network physical layers are RS-485 and LIN .
UART Support for Massive Operating Systems
The widespread use of UART in digital technology has predetermined the integration of support for this interface in the API of many operating systems. Typically, this interface appears in the OS documentation as a COM port or serial port .
Microsoft Windows
Serial ports in Win32 work like files. To open the port, use the CreateFile function. There can be many ports, therefore they are designated as COM1, COM2, etc., in the order in which drivers of the corresponding devices are detected. The first 9 ports are available, including as named pipes for data transfer (available by the names "COM1", "COM2", ...), this access method is considered obsolete. It is recommended that all ports be accessed as files (by the names "\\. \ COM1", "\\. \ COM2", ... "\\. \ COMx").
Search for PnP device names in the system is performed by calling SetupDiGetClassDevs. In the registry, there is a section HKEY_LOCAL_MACHINE \ HARDWARE \ DEVICEMAP \ SERIALCOMM, which displays the currently available COM ports.
For each port in the registry has a section. 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 - “Serial10001”, etc.
UNIX
COM ports on a Unix ( Linux ) operating system are character device files. Usually these files are located in the / dev directory and are called
- ttyS0 , ttyS1 , ttyS2 , etc. on Linux
- ttyd0 , ttyd1 , ttyd2 , etc. (or ttyu0 , ttyu1 , ttyu2 , etc., starting with version 8.0) on FreeBSD
- ttya , ttyb , ttyc , etc. on Solaris
- ttyf1 , ttyf2 , ttyf3 , etc. on IRIX
- tty1p0 , tty2p0 , tty3p0 , etc. in HP-UX
- tty01 , tty02 , tty03 , etc. in Digital Unix
- ser1 , ser2 , ser3 , etc. in QNX
For programmatic access to the COM port, it is necessary to open the corresponding file for reading / writing and make calls to the special functions tcgetattr (in order to find out the current settings) and tcsetattr (to set new settings). You may also need to make ioctl calls with specific parameters. After that, when writing to a file, data will be sent through the port, and when reading, the program will receive already received data from the COM port buffer.
Devices with the names “ttyxx” are used as server devices, that is, the application that opened this device usually expects an incoming call from the modem. The classic default application is getty , which waits for an incoming call, then configures the COM port according to the configuration files, displays “login:” there, accepts the username and starts the “login Username” command as a descendant, with standard input and output redirected to the COM port. This command, in turn, requests and verifies the password, and if successful, launches (not as a descendant, but instead calls itself execve in the same process) the default user shell specified in the / etc / passwd file.
This technology historically arose in the 1970s, when UNIX used computers like PDP-11 (in the USSR the series was called SM computers ) or VAX , which allowed connecting many terminals for many users to work. The terminals — and, therefore, the entire user interface — were connected via serial ports, with the possibility of connecting a modem instead of a terminal and then dialing up to a computer by telephone. There is still a terminal stack in UNIX-like OSs, and usually 3 terminal implementations - a serial port, a screen text mode console + keyboard, and a “loopback” to one of the open files of the control application (such as telnetd, sshd and xterm are implemented).
Serial port client devices designed to make outside calls are called cuaxx on many UNIX (not all).
Since the serial port in UNIX is accessible only through the terminal stack, it can be the control terminal for processes and groups (send SIGHUP when disconnecting from the modem and SIGINT when pressing Ctrl-C), at the kernel level, support editing the last entered line with the arrow keys, and etc. To disable this feature in order to turn the device into a “pipe”, ioctl calls are required for the byte stream.
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 [2] .
Android
Since Android runs on the Linux kernel, working with COM ports in Android is basically the same as working in Linux, but keep in mind that you need root privileges to work in Android.
Virtual Ports
Currently, UART-based physical interfaces have virtually disappeared from consumer digital technology. However, the ease of use and the abundance of software that used access to external devices through the COM port forced the developers of devices connected to computers to create virtual COM port drivers ( VCP - virtual COM port). That is, COM ports for which there is no corresponding hardware UART.
Communication Protocols
Only in very rare tasks is it permissible to send a direct data stream through UART. As a rule, it is necessary to indicate the beginning and end of the data block; provide data integrity control and restore lost items; control the data flow to prevent overloading the input buffer, etc. For these and many other purposes, they come up with communication protocols - agreements on special data sets exchanged between both computer systems to successfully complete the task of establishing communication and transferring basic data. Protocol algorithms depend on the tasks that are assigned to the system, and the features of the physical layer of UART. The protocol algorithm is usually implemented programmatically, rather than hardware.
There are a wide variety of communication protocols designed for use with UART. The most famous:
- MODBUS . A family of request-response protocols popular in industrial automation. They are focused on controlling equipment with short teams.
- AT commands of telephone modems. A set of text commands that allow you to control the modem when establishing a connection.
- PPP - the protocol was widely used when connecting to the Internet through a modem. Allows you to authenticate the user with the provider, encrypt data, etc.
- IrDA is a protocol family for the optical wireless physical layer.
Standardization
The idea of asynchronous data transfer appeared in those distant times, when standardization was still little taken care of and the best that could be expected from suppliers of disparate solutions was the open publication of algorithms for the operation of their products. Actually, that's why there is no UART standard as such, but the logic of UART operation is described as part of the product in many other standards: current loop , RS-232 , ISO / IEC 7816 , etc.
Links
See also
- Serial port
- RS-232
- MAX232
- Serial Peripheral Interface (SPI)
- Bus (computers)
- Microcontroller
Notes
- ↑ Determining Clock Accuracy Requirements for UART Communications
- ↑ Installing a COM port card in a computer (inaccessible link) . Date of treatment June 8, 2014. Archived May 15, 2011.