RS232介绍
RS-232是美国电子工业联盟制定的串行数据通信的接口标准,原始编号全稱是EIA-RS-232。它广泛用于计算机串行接口外设连接。 RS-232C标准,其中EIA代表美国电子工业协会,RS代表推荐标准,232是标识号,C代表RS232的第三次修改,在这之前,还有RS232B、RS232A。
目前的最新版本是由美国电信工业协会(TIA, Telecommunications Industry Association,由EIA所分出的一个组织)所发行的TIA-232-F,它同时也是美国国家标准ANSI/TIA-232-F-1997(R2002),此标准于2002年受到再确认。在 1997年由TIA/EIA发行当时的编号则是TIA/EIA-232-F与ANSI/TIA/EIA-232-F-1997。在此之前的版本是TIA/EIA-232-E。
它规定连接电缆和机械、电气特性、信号功能及发送过程。其他常用电气标准还有EIA-RS-422-A、EIA-RS-423A、EIA-RS-485。
目前在IBM PC机上的COM1、COM2接口,就是RS-232C接口。RS-232对电气特性、逻辑电平和各种信号线功能都作了规定。
由于RS-232-C的重大影响,即使自IBM PC/AT开始改用9针连接器起,目前已几乎不再使用RS-232中规定的25针连接器。一般人谈到RS-232此一接口时很有可能指的是RS-232-C。
= = = = = = = =
在电信领域,RS-232 或建议标准 232 最初是 1960 年推出的一种用于数据串行通信传输的标准。它正式定义了连接计算机终端或 PC 等 DTE(数据终端设备)和调制解调器等 DCE(数据电路终端设备或数据通信设备)的信号。该标准规定了信号的电气特性和定时、信号的含义以及连接器的物理尺寸和引脚。
RS-232 标准常用于串行端口和串行电缆。它目前仍广泛应用于工业通信设备中。
与后来的 RS-422、RS-485 和以太网等接口相比,RS-232 的传输速度较低、最大电缆长度较短、电压摆幅较大、标准连接器较大、不具备多点功能和有限的多路传输能力。在现代个人电脑中,USB 已取代了 RS-232 的大部分外设接口功能。
In telecommunications, RS-232 or Recommended Standard 232 is a standard originally introduced in 1960 for serial communication transmission of data. It formally defines signals connecting between a DTE (data terminal equipment) such as a computer terminal or PC, and a DCE (data circuit-terminating equipment or data communication equipment), such as a modem. The standard defines the electrical characteristics and timing of signals, the meaning of signals, and the physical size and pinout of connectors.
The RS-232 standard had been commonly used with serial ports and serial cables. It is still widely used in industrial communication devices.
Compared with later interfaces such as RS-422, RS-485 and Ethernet, RS-232 has lower transmission speed, shorter maximum cable length, larger voltage swing, larger standard connectors, no multipoint capability and limited multidrop capability. In modern personal computers, USB has displaced RS-232 from most of its peripheral interface roles.
RS232 Max Length
RS232 通常使用 9600bps 的数据波特率。这种波特率较低,电缆长度可达约 150 米(约 500 英尺)。
随着电缆上数据传输速度的增加,数据的物理信号很容易耦合到相邻的导线上。这会在电缆上产生噪声。噪声的形式可能是相邻数据线上的垃圾数据。为了减少相邻数据线的噪声影响,电缆的长度应保持较短。导线之间的绝缘层是电容,高频信号很容易通过。长度越短,电容越小,高频信号就越难耦合到相邻电缆上。
下表是根据波特率计算电缆长度的一般指南。请注意,这只是一般指南。电缆的材料和结构也会影响电缆的长度。为安全起见,最好留出 2% 的余量。 如果您真的想进一步拉长电缆长度,请确保您购买的是高质量的 RS232 电缆,并使用更好的串行数据协议来检测数据损坏并进行必要的数据重传。
The RS232 often uses a data baud-rate of 9600bps. This baud-rate is low and the cable length distance can be up to about 150 meters (about 500ft).
As the speed of data transmission increases on the cable, the physical signal of the data can easily be coupled to the adjacent wire. This induces noise onto the cable. The noise can be in the form of garbage data on the adjacent data wire. To reduce the effect of induced noise from the adjacent wire, the length is kept shorter. The insulation between wires is capacitance which high-frequency signals can easily pass over. The shorter length will keep the capacitance lower which makes it harder for the higher-frequency signal to be coupled over to the adjacent cable.
The following table is a general guide to the cable length base on the baud-rate. Please note that this is only a general guide. The material and the construction of the cable also play a part in the length of the cable. To be safe, it is better to have a margin factor of 2. If you really want to stretch the cable length further, ensure that you get yourself a high-quality RS232 cable and also use a better serial data protocol to detect data corruption and do the necessary data re-transmission.
RS232 电缆长度与数据波特率对照表参考指南
RS232 Cable Length to Data Baud-rate table reference guide
你可以很容易地做一个实验来了解相邻导线上的噪声影响。在两个 RS232 设备(或计算机)之间架设 3 根距离为 30 米至 50 米的导线(Tx、Rx、Gnd)。将导线绞在一起或用胶带粘起来,使导线之间的间隙尽可能小。导线之间最好没有间隙。将波特率设置为 19200bps(使用硬件握手)。
向 Tx 线传输一串字节,并观察从 Rx 线返回的垃圾字节。这些垃圾数据是从 Tx 线耦合到 Rx 线的信号。干扰噪声触发了接收器电路,使其以为接收到了有效的 RS232 物理信号。这些在 Rx 通道上接收到的错误触发字节是 Tx 线路产生的噪声。将波特率降至 9600bps。你会发现产生这种垃圾的概率会降低或没有。提高波特率也会增加产生噪音的概率。
You can easily do an experiment to see the effect of noise induced on the adjacent wire. Set up 3 wires (Tx, Rx, Gnd) of 30m to 50m distance between two RS232 devices (or computer). Have the wire twisted or taped up so that the gap between the wires is as small as possible. The best is no gap between the wires. Set up the baud-rate to 19200bps (with hardware handshaking).
Transfer a string of bytes into the Tx wire and observed the garbage bytes returning from the Rx wire. These garbage data are signals from the Tx wire coupled to the Rx wire. The disturbance noise triggered the receiver circuit thinking that a valid physical RS232 signal is received. These mis-triggered bytes received on the Rx channel are the noise induced from the Tx line. Change the baudrate lower to 9600bps. You will notice that the probability of this garbage generated is lesser or none. Increasing the baud-rate will also increase the probability of noise-induced.
RS232信号有效性
在 RS-232(推荐标准 232)中,信号电压被定义为代表二进制状态,通常用于串行通信。该标准为两种可能的状态规定了以下电压电平:
1. 断言状态(逻辑 “0 ”或标记)
- 电压范围: +3 至 +15 伏(相对于信号地线)
- 描述: 在 RS-232 术语中,正电压代表 “断言 ”或 “标记 ”状态,相当于二进制通信中的逻辑 “0”。
2. 非断言状态(逻辑 “1 ”或空白)
- 电压范围: -3至-15伏(相对于信号地线)
- 描述: 负电压表示 “断开 ”或 “空白 ”状态,对应二进制通信中的逻辑 “1”。
要点:
- 与典型的逻辑电平(0V 为逻辑 “0”,正电压为逻辑 “1”)相比,信号电压电平是反相的。
- RS-232 标准允许在确切的电压范围内有一定的灵活性,但在实际应用中,电压通常接近 ±12V。
- 介于 -3V 和 +3V 之间的电压是未定义的,被视为 “死区”,这意味着它们不能可靠地代表任何一种二进制状态。
这一电压范围有助于 RS-232 在相对较长的距离内保持可靠的通信,最长可达 15 米(50 英尺),具体取决于电缆质量和传输速度。
In RS-232 (Recommended Standard 232), signal voltages are defined to represent binary states, typically for serial communication. The standard specifies the following voltage levels for the two possible states:
1. Asserted State (Logical "0" or Mark)
- Voltage Range: +3 to +15 volts (relative to the signal ground)
- Description:** In RS-232 terminology, a positive voltage represents the "asserted" or "mark" state, which corresponds to a logical "0" in binary communication.
2. Deasserted State (Logical "1" or Space)
- Voltage Range: -3 to -15 volts (relative to the signal ground)
- Description: A negative voltage represents the "deasserted" or "space" state, corresponding to a logical "1" in binary communication.
Key Points to Remember:
- The signal voltage levels are inverted compared to typical logic levels (where 0V is logical "0" and a positive voltage is logical "1").
- The RS-232 standard allows some flexibility in the exact voltage ranges, but typically voltages closer to ±12V are common in practical implementations.
- Voltages between -3V and +3V are undefined and considered as a "dead zone," meaning they do not reliably represent either binary state.
This voltage range helps RS-232 maintain reliable communication over relatively long distances, up to 15 meters (50 feet) depending on cable quality and speed of transmission.
在RS-232标准中定义了逻辑一和逻辑零电压级数,以及标准的传输速率和连接器类型。信号大小在正的和负的3-15v之间。RS-232规定接近零的电平是无效的,逻辑一规定为负电平,有效负电平的信号状态称为传号marking,它的功能意义为OFF,逻辑零规定为正电平,有效正电平的信号状态称为空号spacing,它的功能意义为ON。电平有效范围在±3至±15伏之间。根据设备供电电源的不同,±5、±10、±12和±15这样的电平都是可能的。
mark和space是从电传打字机中来的术语。电传打字机原始的通信是一个简单的中断直流电路模式,类似与圆转盘电话拨号的中的信号。Marking状态是指电路是断开的,spacing状态就是指电路是接通的。一个space就表明有一个字符要开始发送了,相应的停止的时候,停止位就是marking。当线路中断的时候,电传打字机不打印任何有效字符,周期性的连续收到全零信号。
其他
压摆率
输入电压的变化决定了 RS232 驱动器的响应速度。这通常称为压摆率。RS232 标准规定了电压慢速上升和下降的最小压摆率,以减少相邻信号之间的串扰。通常,允许的最大压摆率为 30V/µsec。
Slew Rate
The change of input voltage determines the rate at which the RS232 driver responds. This is often termed as slew rate. The RS232 standard maintains a minimum slew rate with slow rise and fall time to reduce the cross-talk between neighbouring signals. Normally, the maximum slew rate allowed is 30V/µsec.
线路阻抗
RS232 驱动器和接收器之间的桥接阻抗是为了最大限度地提高发送器和接收器之间的电压传输。其范围为 3KΩ 至 7KΩ。
Line Impedance
The impedance bridging between RS232 driver and the receiver is defined to maximize the voltage transfer between the transmitter and receiver. It is in the range of 3KΩ to 7KΩ.
运行模式
RS232 设备以单端信号(双线)方式工作。这意味着一根导线传输改变电压,另一根导线接地。单端信号会受到驱动电路和接收电路接地电压差异引起的噪声影响。单端技术的优点是只需较少的导线即可传输信息。
Mode of Operation
The RS232 devices work on single-ended signaling (two wire). This means one wire transmits an altering voltage and another wire is connected to ground. Single-ended signals are affected by the noise induced by differences in ground voltages of the driver and receiver circuits. The advantage of the single-ended technique is, it requires fewer wires to transmit information.
波特率
是指每秒传输的二进制位数。RS232 支持从 110 到 230400 的波特率。常用的波特率有 1200、4800、9600 和 115200。它决定了数据从发送器发送到接收器的速度。
注意:发送端和接收端的波特率必须相同。
Baud rate
It is the number of binary bits transferred per second. RS232 supports baud rates from 110 to 230400. Commonly, the baud rate with 1200, 4800, 9600, 115200 are used. It determines the speed at which data is to be sent from the transmitter to the receiver.
Note: The baud rate has to be same at both the transmitter side and receiver side.
What is Handshaking?
握手是发送方(发射方)和接收方之间交换信息信号的过程。这些信号在发送器和接收器之间建立通信链路。在 RS232 中,有两种类型的握手。它们是硬件握手和软件握手。
Handshaking is the process of interchanging information signals between the sender (transmitter) and receiver. These signals build a communication link between the transmitter and receiver. In RS232, there are two types of handshaking. They are hardware handshaking and software handshaking.
DB9 和 DB25 连接器用于握手。不进行握手时,只有 TxD(发送器)和 RxD 交叉耦合。其他引脚、RTS、CTS、DSR 和 DTR 以环回方式连接。
为了使用握手技术,RTS 和 CTS 被交叉耦合。此外,DTR 和 DSR 也以交叉模式连接。
The connectors DB9 and DB25 are used for handshaking purpose. When no handshaking is performed, only the TxD (Transmitter) and RxD are cross-coupled. Other pins, RTS, CTS, DSR, and DTR are connected in loopback fashion.
To use the handshaking technique, RTS and CTS are cross-coupled. Also, DTR and DSR are also connected in cross mode.
Why to use Handshaking?
为了不丢失数据地发送和接收信息,有必要在发送器和接收器之间保持稳健的通信。为此,需要使用缓冲区。缓冲区是一个临时存储位置,允许发送方和接收方存储数据,直到彼此以不同的速度处理信息。
To send and receive the information without loss of data, it is necessary to maintain robust communication between the transmitter and receiver. To do that, buffer is used. Buffer is a temporary storage location which allows the transmitter and receiver to store the data until the information is processed by each other at different speeds.
Data flow:
在上图中,发送器和接收器都有各自的缓冲区。发送缓冲区保存要发送到接收器的字符。而接收缓冲区则保存从发送器接收到的字符。如果发送器以较高的速度发送数据,接收器可能无法接收。在这种情况下,接收器就会错过字符 “C”。为了避免这种情况,需要使用握手功能。握手允许发送器和接收器设备在通信开始前达成一致。
In the above diagram, the transmitter and receiver have their own buffer. The transmit buffer holds the characters to be sent to the receiver. While the receive buffer holds the characters received from the transmitter. If the transmitter sends data at a higher speed, the receiver may fail to receive. In this case, character ‘C’ is missed by the receiver. To avoid this, handshaking is used. Handshaking allows the transmitter and receiver device to agree before the communication is going to start.
Hardware Handshaking
数据传输和接收的流量控制是通过硬件握手完成的。它使用控制信号 DTR、DSR、RTS 和 CTS 信号。通常,在计算机和调制解调器之间建立通信时,会使用 RTS 和 CTS 信号。
它可阻止接收器缓冲区中的数据被替换。这些信号保持高电平状态(逻辑 “1”)以激活握手。
The flow control of data transmission and reception is done using hardware handshaking. It uses control signals DTR, DSR, RTS and CTS signals. Typically, when establishing communication between a computer and modem RTS and CTS signals are used.
It stops the data being replaced in the receiver buffer. The signals are kept in a high state (logic ‘1’) to activate handshaking.
Software Handshaking
这种类型的握手使用两个 ASCII 字符来启动-停止通信。因此,这被称为软件流量控制。软件握手使用 XON/XOFF 字符来控制串行通信。XON “表示 Ctrl+Q 或 ASCII 字符 11,而 ”XOFF "表示 Ctrl+S 或 ASCII 字符 13。这种握手方式需要 3 根导线。它们是 TXD、RXD 和信号 GND。
启用 “XOFF ”字符后,通信将被关闭,直到发送器收到 “XON ”字符。在某些情况下,接收器缓冲区可能会超载,导致接收器自动向发送器发送 “XOFF ”字符。
This type of handshaking uses two ASCII characters for start-stop communication. Hence, this is known as software flow control. Software handshaking use XON/XOFF character to control the serial communication. ‘XON’ represents Ctrl+Q or ASCII character 11, whereas ‘XOFF’ represents Ctrl+S or ASCII 13. This handshaking requires 3 wires. They are TXD, RXD and signal GND.
When ‘XOFF’ character is enabled, the communication is closed until ‘XON’ character is received by the transmitter. In some cases, the receiver buffer may overload which causes the receiver to send ‘XOFF’ automatically to the transmitter.
Difference between RS232 and UART
RS232 和 UART 协议的主要区别在于电压水平。除此之外,它们都支持半双工和全双工通信。
微控制器不能承受 RS232 电压,可能会损坏。为了避免这种情况,使用了 UART(通用异步发送接收器)。它以串行形式发送和接收数据。为了进行电压电平转换,在 UART 和串行端口之间使用了 RS232 驱动集成电路,如 MAX232。
The main difference between RS232 and UART protocol is the voltage levels. Apart from this, they both supports half duplex and full duplex communication.
Microcontrollers don’t tolerate RS232 voltages and may be damaged. To avoid this, UART (Universal Asynchronous Transmitter Receiver) is used. It sends and receives the data in serial form. To do the level conversion of voltages, RS232 driver IC such as MAX232 is used between the UART and serial port.
RS232-UART
Advantages
RS232 的优势使其成为系统间通信的标准串行接口,并具有以下优点。
* 协议设计简单。
* 硬件开销小于并行通信。
* 短距离应用的推荐标准。
* 兼容 DTE 和 DCE 通信。
* 用于开发的协议成本低。
The advantages of RS232 make it as a standard serial interface for system to system communication and also for the following benefits.
* Simple protocol design.
* Hardware overhead is lesser than parallel communication.
* Recommended standard for short distance applications.
* Compatible with DTE and DCE communication.
* Low cost protocol for development.
Disadvantages
RS232 协议的局限性在于,它不支持全双工通信,而且是单端协议,会改变接地电位。此外,较长的电缆长度会在串行通信过程中产生干扰。因此,该协议不利于长距离通信。
The limitations of RS232 protocol are, it doesn’t support full-duplex communication and it is a single-ended protocol which shifts the ground potential. Moreover, the longer cable length introduces cross talk during serial communication. Hence, this protocol is restricted for long distance communication.
Applications
RS232 通信用于不同的应用领域。其中包括
* 电传打字机设备。
* 解调器应用。
* 计算机 COM 端口接口。
* 嵌入式系统调试。
* 调制解调器和打印机
* 手持设备
* 数控控制器、软件调试器等。
* 条形码扫描器和销售点 (POS) 终端。
RS232 communication is used in different applications. Some of them are:
* Teletypewriter devices.
* Demodulator applications.
* PC COM port interfacing.
* In embedded systems for debugging.
* Modems and printers.
* Handheld equipment.
* CNC controllers, Software debuggers etc.
* Barcode scanners and Point of Sales (POS) terminals.
参考:
https://www.usconverters.com/index.php?main_page=page&id=61
RS232 Pin Out | Connector Reference Guide
RS232 Pin Out | Connector Reference Guide
RS232 cable (wiring for Crossed / Straight)
https://en.wikipedia.org/wiki/RS-232
https://zh.wikipedia.org/zh-cn/RS-232
https://www.codrey.com/embedded-systems/rs232-serial-communication/