[Switch] RS232 serial communication details

Source: Internet
Author: User

Serial Port is a very common device communication protocol on the computer.

---------------------------------

Serial Port Pin definition:

 

9 Cores Signal Direction from Abbreviations Description
1 Modem CD Carrier Detection
2 Modem Rxd Receive data
3 PC Txd Send data
4 PC DTr Data Terminal preparation
5   Gnd Signal Location
6 Modem DSR Communication device preparation
7 PC RTS Send request
8 Modem CTS Allowed to send
9 Modem Ri Bell indicator

When two serial ports are connected, the receiving data pin is connected to the sending data pin, and the signal is connected accordingly.

 

---------------------------------

Electrical Characteristics of serial ports:

1) RS-232 serial port communication is the longest distance is 50 feet

2) RS232 achieves bidirectional transmission, full duplex communication, and a maximum transmission rate of 20 kbps

3) the number transmitted on the RS-232C adopts the negative logic and is symmetric with the ground

Logic 1:-3 ~ -15 V

Logic 0: + 3 ~ + 15 V

Therefore, when connecting to a single-chip microcomputer, you often need to add a level conversion chip:

---------------------------------

Serial Communication parameters:

A) baud rate: The RS-232-C standard data transmission rate per second 50, 75, 100, 150, 300, 600, 1200, 2400, 4800.

B) Data bit: The standard values are 5, 7, and 8 bits. The setting depends on the information you want to transmit. For example, the standard ASCII code is 0 ~ 127 (7-bit); the extended ASCII code is 0 ~ 255 (8 digits ).

C) Stop bits: used to represent the last bits of a single package. The typical values are 1, 1.5, and 2 bits. Because the number is scheduled on the transmission line, and each device has its own clock, it is very likely that there is a small non-synchronization between the two devices in the communication. Therefore, the stop bit is not only the end of the transmission, but also the opportunity for the computer to correct the clock synchronization.

D) parity bit: a simple error checking method in serial communication. In the case of parity and odd parity, the serial port sets the parity bit (one digit after the data bit), and uses a value to ensure that the transmitted data has even or Odd logic highs. For example, if the data is 011, the parity check bit is 0 to ensure that the number of digits with high logic is an even number. If it is an odd check, the check bit is 1, so there are three logic High.

---------------------------------

Serial Communication transmission format:

In serial communication, when the line is idle, the TTL level of the line is always high, and the reverse RS232 level is always low. The start of a Data RS232 line is high, and the end of the RS232 line is low. Data is always transmitted from low to high. When reading an oscilloscope, the left side is the data height.

For example, for hexadecimal data 55aah, when 8-Bit Data bit, 1-bit stop bit transmission, its waveform 1 (TTL level) on the signal line and figure 2 (RS-232 level.

55 H = 010101b, take the inverse value 10101010b, add a start bit 1, a stop bit 0, and the 55h data format is 1010101010b;

Aah = 10101010b, take the reversed value 01010101b, add a start bit 1, a stop bit 0, and the 55h data format is 1101010100b;

---------------------------------

Receiving process of serial communication:

(Asynchronous communication: the receiver and the transmitter have their own clock. synchronous communication: the transmitter and the receiver are controlled by the same clock source. RS232 is asynchronous communication)

(1) When communication starts, the signal line is idle (logic 1). When a hop from 1 to 0 is detected, the "receive Clock" is counted.

(2) When 8 clocks are counted, the input signal is detected. If the input signal is still low, it is confirmed that this is the start position, rather than the interference signal.

(3) After the receiving end detects the start bit, it detects the input signal once every 16 receiving clocks and uses the corresponding value as the D0 BIT data. If it is logical 1, it is used as data bit 1; if it is logical 0, it is used as data bit 0.

(4) Check the input signal once every 16 receiving clocks and use the corresponding value as the D1 BIT data ....., Until all data bits are input.

(5) Check the checkpoint P (if any ).

(6) After receiving the specified data bit count and check bit, the communication interface circuit wishes to receive the stop bit S (logic 1). If logic 1 is not received at this time, an error occurs, set the frame error flag in the Status Register. If no error occurs, perform parity check on all data bits. If no verification error occurs, send the data bit from the shift register to the data input register. If the verification is incorrect, set the parity error mark in the Status Register.

(7) after receiving all the token information, the High Level on the line is used as the idle bit.

(8) When the signal becomes low again, it starts to go to the next detection.

---------------------------------

Single-Chip commonly used 11.0592m crystal oscillator, this strange number has a history:

The baud rate is 9600bps. Each Bit Width T1 = 1/9600 S.

Crystal cycle t2 = 1/11. 0592/1000000 s

Single-Chip Microcomputer machine cycle T3 = 12 * t2

T1/T3 = 96

That is, for the serial port of 9600bps, the single-chip microcomputer samples it at a rate of 96 times.

If the MCU crystal oscillator is used incorrectly, the serial port will receive an error code.

---------------------------------

RS485 and rs422

RS485 bus, when the communication distance is dozens of meters to kilometers, widely used RS-485 serial bus standard. RS485 adopts balanced transmission and differential reception, so it has the ability to suppress common mode interference. In addition, the bus transceiver is highly sensitive and can detect voltage as low as 200mV. Therefore, the transmission signal can be recovered from kilometers away. RS485 adopts the half-duplex mode. At any time, only one node is in the sending status. Therefore, the sending circuit must be controlled by the enabling signal. RS485 is very convenient for Multi-Point interconnection and saves many signal lines. The application RS485 can be networked to form a distributed system, which allows a maximum of 32 drivers and 32 receivers in parallel.

Rs422 bus, RS485 and rs422 circuit are basically the same principle, are sent and accepted in a differential mode, do not need a digital ground. Differential operation is the root cause of long transmission distance at the same rate. This is the fundamental difference between the two and RS232, because RS232 is a single-ended input and output, at least three lines (asynchronous transmission) of the digital ground transmission line and the receiving line are required during duplex operation. Other control lines can be added for synchronization and other functions. Rs422 can work in full duplex mode without affecting each other through two pairs of twisted pair wires, while RS485 can only work in half duplex mode, but it only needs one pair of twisted pair wires. Rs422 and RS485 can transmit 1200 meters under 19kpbs. Connect devices to the new transceiver line.

[Switch] RS232 serial communication details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.