UART (Universal asynchronous transmitter ER/transmitter)
General asynchronous transceiver
UART is a chip used to control computers and serial devices. One thing to note is that it provides an interface to the RS-232C data terminal device so that the computer can communicate with the modem or other serial devices that use the RS-232C interface. As part of the interface, UART also provides the following functions:
Converts parallel data transmitted from within a computer to the output serial data stream.
Converts serial data from outside the computer into bytes for devices that use parallel data inside the computer.
Add the parity bit to the output serial data stream and perform the parity check on the data stream received from the outside.
Add the start and stop mark to the output data stream and delete the start and stop mark from the received data stream.
Handle the interrupt signal sent by the keyboard or mouse (the keyboard and mouse pass are also serial devices ).
It can manage the synchronization between computers and external serial devices.
Some of the more advanced uarts also provide the buffer for the input and output data. Now the newer UART is 16550, which can store 16 bytes of data in the buffer before the computer needs to process the data, generally, the UART is 8250. If you buy a built-in modem, the modem usually has a 16550 UART.
1. Features of UART Protocol
1.1 Data Sampling
UART protocol is implemented between devices standard protocol for low-speed data communication. Because the clock does not need to be sent at the time of sending, the Protocol is asynchronous. UART link typical 38400 , 9600 Porter. such as 1 , UART character format is 1 start bit, 5 ~ 8 data bits, 1 address bit or (optional), and 1 stop bit.
Because the receiver and transmitter work asynchronously, they do not need to be connected to the receiving and sending clock. The receiver uses the input data stream height sampling method. Generally, the sampling value is 16 and the bit value is determined based on the sampling value. By convention, three values in the middle of 16 sample values are used.
1.2 UARTFrame Differentiation
UART a parameter MAX-IDL that is used to set the number of idle characters. Once one character is received online, the UART Controller starts counting idle characters received. If multiple idle characters in a MAX-IDL are received before the next data character is received, the idle time is generated and the buffer is disabled. Sequentially send a one-stop request to the CPU 32 + core, requiring receiving data from the buffer zone. Therefore, the MAX-IDL provides a convenient way to differentiate frames in UART mode.
The number of idle characters is calculated based on the following formula: 1 (start) + Data Length (5, 6, 7, 8) + 1 (if parity is used) + stop (1 ). For example, 1 (starting), 8-bit data, no validation, 1 stop bit, the idle character MAX-IDL is 10 characters.
1.3 UARTAddress Recognition
In a multi-site system, there may be more than two sites on the network, each of which has a specific address. 2. Two examples of this structure. Frames composed of many characters can be broadcasted. The first character is the destination address. To implement this function, the UART frame is extended by one bit to distinguish the address character from the normal data character.
UART can be set to operate in a multi-site environment, which supports the following two modes:
When the address matches one of the two preset values, the UART Controller automatically checks the incoming address characters and receives subsequent data.
The UART Controller in non-automatic multi-site mode receives all data. A single address character is always written into a new buffer zone.
To sum up, The UART protocol adopts a mechanism to determine bit values through data sampling. It has a simple and accurate frame setting mode and is widely used in multi-site systems, supports automatic multi-site and automatic multi-site modes to differentiate addresses and data.
2. Several important registers
In embedded development, it is critical to understand and correctly configure registers. There are several important registers for the UART protocol of the MPC860, which are: full configuration register, baud rate configuration register, communication processing command register, SCC common mode register, sending and receiving buffer descriptor, UART specific parameters, SCC protocol dedicated mode register, SCC protocol event register UART shielding register.
The Pipe Full configuration register is generally for receiving and sending two pipe full, with open and leak registers, data registers, data direction registers, they can be set as capable of serial channel output and as input and output ports. The baud rate configuration register directs the baud rate to the serial port used and configures the baud rate. The communication processing command register is mainly used to determine whether the command is issued and whether the transfer is blocked. SCC common mode registers are mainly used for protocol selection and Transmission Format configuration. The sending and receiving buffer descriptor is used to send and receive data and determine whether the received data is an address, a data error, and so on. Specific UART parameters are used to partially initialize UART. The special mode register of SCC protocol is mainly used to set the UART to be in the Automatic multi-station and non-automatic multi-station modes. Event registers are mainly used to determine whether a receiving or sending interruption occurs. Shield registers are mainly used for receiving and sending enable.
Therefore, for the UART protocol, the above registers are very important, they mainly complete the baud rate configuration, protocol selection, sending and receiving judgment and processing.
UART & RS232 & Com
UART is the abbreviation of universal asynchronous transceiver (asynchronous serial communication port). It includes interfaces and bus standard specifications such as RS232, rs499, rs423, rs422, and RS485, UART is a general term for asynchronous serial communication ports.
RS232, rs499, rs423, rs422, and RS485 are interface standards and bus standards corresponding to various asynchronous serial communication ports, it specifies the electrical characteristics, transmission rate, connection characteristics and mechanical characteristics of the communication port. It actually belongs to the concept of the physical layer (bottom layer) in the communication network and has no direct relationship with the communication protocol. Communication Protocol is a concept of the data link layer (the previous layer) in the communication network.
The comport is short for asynchronous serial communication ports on PCs. For historical reasons, the ibm pc external interface is configured as RS232, which becomes the actual default standard in the PC industry. Therefore, the current comport of the PC is RS232.
UART (Universal asynchronous transmitter ER/transmitter) isGeneral asynchronous transceiver, Working on the data link layer. Contains RS-232, RS-422, RS-485 serial communication and infrared (IRDA) and so on. As a low-speed communication protocol, UART is widely used in communication and other occasions. UART can be divided into two types: Parallel Communication and serial communication.
Asynchronous Serial Communication ProtocolAs a UART, each character of the transmitted data is transmitted one by one. Figure 1 shows the working mode:
Figure 1
The meanings are as follows:
Start position: Sends a logic "0" signal, indicating the start of the transmission character.
Data Location: Followed by the start position. The number of data bits can be 4, 5, 6, 7, 8, and so on. Generally, ASCII code is used. Transmits data starting from the second BIT and locates it by the clock.
Parity bit: After the data bit is added, the number of digits of "1" should be an even number (even verification) or an odd number (odd verification) to verify the correctness of the data transfer.
Stop bit: Indicates the end of a character. It can be 1-bit, 1.5-bit, or 2-bit high.
Idle bit: In the logical "1" status, it indicates there is no data transfer on the current line.
Baud Rate: A pointer to the data transfer rate. The number of binary digits transmitted per second. For example, if the data transfer rate is 120 characters/second, and each character is 10 characters, the Transmission baud rate is 10 × 120 = 1200 characters/second = 1200 Potter.
In an embedded system or computer, the serial port is not directly controlled, but is controlled through the SCI (serial communication interface) module. (Note: "Sci" is first named after Motorola micro-serial-port microcontroller, and "UART Controller" is another term of SCI) Many commonly used chips contain SCI, for example, the arm's S3C2410X chip is embedded with three serial interface controllers, while the soft-core chips such as NIOS can use the UART (RS232) IP address to control UART. PC usually uses 16650 UART, 16750 uart and other control serial ports.
If you implement a software UART, it takes a lot of time for the UART to check the serial activity of the port pins, so that the applicationProgramThis makes the software UART meaningless. Fortunately, this is not the case. Let's take a look at the Standard 10-bit asynchronous serial Protocol (including a start bit, a stop bit, and eight data bits) when sending and receiving one character (1 ).
Figure 1: Timing Diagram of Standard 10-bit asynchronous serial protocol for sending and receiving characters.
After a sending or receiving operation is started, serial UART (software or hardware UART) does not need to continuously monitor the I/O line. When sending a single character, for each bit cycle, UART only needs to drive the status of the sending signal line once, from the start bit to the 8 Data bit until the second bit sets the level of each bit in turn. When receiving a character, the UART starts to work on the first descent edge, and then only needs to sample the Signal Status of the receiving line in the center of each time slot.
We can use a one-to-one state machine to characterize the behavior of the software UART. One State machine is used to send characters, and the other is used to receive characters. For a full-duplex UART, the two state machines run in parallel and require two independent timer interruptions. Both state machines have active and passive modes. The sending State Machine jumps out of the idle state when receiving a character to be sent, and returns to the idle state after sending in the delayed bit. The receiving State Machine jumps out of idle state when detecting a descent edge on the receiving line. After the initial low-level state is detected (this State indicates that the start position has started), the number of time slots in the position is decreased, and each signal bit on the signal line is sampled as required, including the stop position.
To avoid unnecessary occupation of too much time for the main application, the UART state machine should be activated by some periodic timer-based interruptions. The detection of the initial descent edge of the receiving line requires independent processing of external interruptions triggered by an edge. If the timer of a state machine is set to send an interrupt request every bit cycle, the state machine can execute any required operations when each interrupt is triggered (and if necessary, can also enter the next state ). Used to implement the state machineCodeOptimization should be made as much as possible, because the code runs continuously in the background as long as the software UART is active.
Address: http://www.xxlinux.com/linux/article/network/app/20071106/11626.html