RS-232串行接口
RS-232是在任何时候都常用的接口之一。它不仅已经被内置于每台PC,而且已被内置于从微控制器到主机的多种类型的电脑和与它们连接的设备。RS-232的最通常得用处是连接到一个Modem,其他拥有RS-232接口的设备包括打印机,数据采集模块,测试装置和控制回路。你也可以将RS-232用在任何类型得计算机之间的简单连接中。
RS-232是设计来处理两台设备之间的通信的,距离限制为50到100f,这决定于波特率和电缆类型。因为RS-232端口被广泛应用,它的另一个用途是与一个将这个接口转换成另一种类型的适配器相连。例如,一个简单的回路将一个RS-232端口转换成一个RS-485端口,这个端口可以和多台设备相连并且可以使用更长的导线连线。
RS-232连接使用非平衡导线。尽管一个非平衡的状态听起来像是一些应该避免的东西,在这里它仅仅是指导线中的信号的电气特性。在一条非平衡导线中,信号电压加到一条导线上,所有的信号电压都使用一个公共的接地线。这种类型的接口的另一个术语是单端。
特性
RS---232有几个优点:
(1) 它是无处不在的。每一台PC机都有一个或更多的RS---232端口。更新的计算机现在支持其他诸如USB这样的串行接口,但是RS---232可以做很多USB无法做的事情。
(2) 在微控制器中,接口芯片使得将一个5V串口转换成RS-232变得很容易。
(3) 连接距离可以达到50到100ft。大多数的外设接口都不会用于太长的距离。USB连接最长可以达到16ft,PC机的并口打印机接口与主机的距离可以达到10到15ft,或者利用IEEE-1284B型驱动器可以达到30ft。但是RS-232可以使用更长的电缆。如果每一个RS-232端口与一个Modem相连,你可以使用电话网在世界范围内发送数据。
(4) 对于一个双向连接,你只需要3条导线。一个并行连接一般需要8条数据线,两条或者更多的控制信号线,和几条接地线。所有的导线和更大的连接器使得价格累计起来就比较高了。
RS-232的缺点包括以下这些:
(1) 如果连接的另一头需要并行数据,它不得不将这个串口数据转换成并行数据。但是利用一个UART,这很容易实现。
(2) 串口是如此的有用,以至于寻找一个未用的串口可能会比较困难。PC机可以有多个串口,但是一个系统可能无法为每一个串口分配一个唯一的中断请求信号。大多数的微控制器只有一个硬件串口。
(3) 在一个连接中不能有超过2台以上的设备。
(4) 指定的最大数据传输速率是每秒20000位。但是,很多接口芯片可以超过这个数值,尤其是在短程连接上。
(5) 很长的连接需要一个不同的接口。
双向RS-232通信的3个基本信号如下:
TD:将数据从DCE传输到DCE也被称作TX和TXD。
RD:将数据从DCE传输到DTE。也被称作RX和RXD。
SG:信号地。也被称作GND和SGND。
电压
RS-232的逻辑电平用正负电压表示,而不是只用5V TTL和CMOS逻辑的正电压信号表示。在一个RS-232的数据输出(TD),一个逻辑0被定义为等于或者高于+5V,而一个逻辑1被定义为等于-5V或者比低于-5V。换言之,信号使用负逻辑,在这种逻辑中,负的电压为逻辑1。
控制信号使用相同的电压,但是使用的是正逻辑。一个正的电压表示这项功能为开,而一个负的电压表示这个功能为关。
RS-232接口芯片反向转换这些信号。在一个UART的输出引脚,一个逻辑1 数据位或者一个关控制信号接近于5V,它在RS-232的接口产生一个负电压。一个逻辑0数据位或者一个开控制信号接近于0V,它在RS-232接口产生一个正电压。
因为一个RS-232接收器可能位于一条长电线缆的末端,等到信号到达接收者的时候,它的电压可能已经削弱了或者加载了噪声信号。考虑到这种情况,在接受方最低要求的电压要比在驱动器处要低。一个比+3V高得多的输入在RD处是一个逻辑0,或者在一个控制输入处是一个开。一个比-3V要低得多的输入在RD处为一个逻辑1,或者在一个控制输入处为一个关。根据这个标准,在-3V和+3V之间的一个输入的逻辑电平没有定义。
噪声容限,或者电压容限,是输出电压和输入电压的区别所在。RS-232的大电压波动导致一个比5V TTL逻辑宽得多的噪声容限。例如,即便一个RS-232驱动器的输出为最小的+5V,它也会在接受方削弱或者噪声峰值大到2V,并且仍旧是一个有效逻辑0。很多RS-232输出有更宽的电压波动:±9V和 12V是很平常的事情。这些都导致更宽的噪声容限。最大允许的电压波动是 15V,尽管接受方必须不受任何损害地处理高达 25V的电压。
使用的另外两个与RS-232有关的术语是Mark和Space。Space是逻辑0,而Mark是逻辑1。这两个术语是多年以前机械记录仪二进制数据的,他们分别代表物理标记和空白。
计时限制
TIA/EIA-232包括最小和最大计时规定。所有的RS-232接口芯片都符合这个规定。
指定的旋转速度限制了接口的最大比特率。旋转率是当输出切换时电压变化的快慢的量度,并且描述了一个输出的电压变化的瞬间速度。一个RS-232驱动器的旋转速度必须是每毫秒30V或者更少。
限制旋转速度的好处是它通过事实上消除由于电压偏转引发的问题来改进信号质量,电压偏移发生在传输有着快速上升和下降节拍的信号的长距离连线上。
但是旋转速度也限制了一个连接的最大速度。在30V/us的速度下,一个输出需要0.3us从+5V切换到-5V。RS-232的规定的最大波特率为20kbps,这个速度转换成一个比特宽度为50us,或者在允许的最快旋转速度下为166倍的切换时间。
事实上,因为UART在位的中间附近读取输入数据,并且还因为大多数的时间参考时钟是非常准确的,你可以安全的使用短到5到10倍的切换时间的位的宽度。考虑到这些,有的接口芯片允许115kbps或者更高的波特率,即使这违反了这个标准的建议。
除了有一个最大的切换速度之外,RS-232 驱动器还必须符合最低标准以确保信号不在逻辑状态之间的未定义区域停留。对于控制信号和其他40bps和更低的信号,信号线必须花费不超过1ms的时间在有效的逻辑1和逻辑0之间的
传送区域,对于其他数据和时间信号,这个限制是4%的位宽,或者在20bps下为2us。信号的上升和下降次数也要尽可能的接近相等。
在5V逻辑和RS-232之间转换
很多微控制器有异步串口,但是它们的输出和输入使用5V逻辑而不是使用RS-232电压。将5V落连接到一个RS-232端口需要转换到RS-232电平和从RS-232电平转换到5V逻辑。
利用5V逻辑,我假定了TTL或者CMOS逻辑芯片使用的逻辑电平,这些芯片是由一个单一的+5V电源供电,信号电平以接地电平作为参考。
对于TTL逻辑,一个逻辑低输入不高于0.8V。一个逻辑高输出必须至少为2.4V,而一个逻辑高输入必须至少为2V。利用这些逻辑电平,一个接口可以有0.4V的噪声信号而不至于产生错误。
这些逻辑电平应用在初期的,标准的7400系列的TTL逻辑和他的派生系列,包括74LS74F和74ALS TTL。较早的利用NMOS技术制造的微控制器也使用这些逻辑电平。
大多数的CMOS芯片定义了不同的逻辑电平,并且有更宽的噪声容限。一个逻辑低CMOS输出不高于0.1V,而一个逻辑低输入可以高达20%的电源电压,或者对于5V的电源输入可以达到1V。一个逻辑高输出至少为4.9V,而一个逻辑高输入必须至少达到电源电压的70%,或者对于5V电源输入而言达到3.5V。使用这样的逻辑电平的系列包括4000系列,74HC和74AC。
有的CMOS芯片有TTL兼容输出。这是得他们可以直接和CMOS或者TTL逻辑项链。遵循这个惯例的芯片包括74HCT逻辑系列和大多数的微控制器。
RS-232 Interface
RS-232 is one of the normally used interfaces at any time, it not only built in every PC-set, but also built in any types of computers which are from microcontroller to host computers, and equipment connected with them. The general usage of RS-232 is to connect a modern, the other arrangements with RS-232 interfaces include printer, data collection module, testing device and control loop. RS-232 can be also used in the simple link of any type of computer.
RS-232 is designed to deal with the communication between two arrangements with distance limitation from 50 to 100ft, which depend on Potter rate and type of electric cable. Because of wide application of RS-232 port, its other usage is to link another type of adapter converted form the port.
For example, a simple loop changes a RS-232 into a RS-485 port. The port can be link with several devices by means of a long lead. Non-equilibrium lead is used to linked to RS-232. Although non-equilibrium should something avoidable, it only refers to the electric property of the signal in lead. In a non-equilibrium lead, signal voltage is applied to another lead, all has another technical term “signal end”.
Advantages in RS-232
RS-232 is used everywhere. Every PC-set has one or more RS-232 ports. The renewed computers sustain other serial interfaces like USB. But RS-232 can do many things which USB can’t do.
In the micro-controller interface chip can be easily used to change into RS-232.
The jointing distance can reach 50-100ft. Many external interfaces are not used for too long distance. The longest distance joint of USB can reach 16ft. The distance between parallel printer interface on the PC-set and the host computer can reach 10 to 15ft, or 30ft by using Type TEEE-1284B driver. But RS-232 can use the longer electric cable.
If every RS-232 port is linked with a modern, Telephone network can used to send data in the rage of the world.
For a double link, 3 leads are needed. A parallel circuit generally needs 8 data lines, two or more control signal lines and ground wires。It is more expensive if more leads and bigger connectors are used.
Disadvantages in RS-232
If one side of link needs parallel data, it has to transform serial into parallel data. But if it is easily realized a UART is used.
Because of the serial port so useful, it is maybe harder to look for a free serial port PC-set may have many serial ports, but a system maybe can’t distribute a sole breaking enquiring signal to every serial port. Most micro-controller only has one hardware serial port.
No more than 2 set in one link.
The biggest designated transmitting rate of data is 2000bits/s.But many interface chip can surpass this numerical value, especially in the short distance link.
A longer link needs a different interface.
3 basic signals of the double RS-232 communication as follows:
TD. Transform data DTE to DCE It’s also called TX and TXD.
RD. Transform data DCE to DTE It’s also called RX and RXD.
SG. Signal land. It’s also called GND and SGND.
Voltage
Logic0 is a positive RS-232 voltage, the logic electric level of RS-232 is indicated with positive-negative, and not only use the positive voltage signal of the 5VTTL and CMOS logic to indicate. In the data logger(TD)of RS-232,a logic0 is defined equal to or higher than +5V, and a Logic1 defined equal to -5V or lower than -5V. In another word, signal use the negative logic, in this logic, the negative voltage is Logic1.
Control signal uses the same voltage, but it uses positive logic. A positive voltage indicates this function is on and a negative voltage indicates this function is off.
RS-232 interface chip transform these signals in reverse. In output pin of one UART, A logic1 datum or a off control signal is close to 5V, it produces negative voltage on the interface of RS-232.A logic0 datum or an on-control signal is close to 0V, it produces a positive voltage on the interface of RS-232.Because of the RS-232 receptor maybe at the end of a long electrical cable, when the signal reaches the receiver, it’s voltage is probably weaker or with the noise signal. In consideration of this circumstance minimum at the receiver should be lower than the voltage at the driver.
An input higher than +3V on the RD are a Logic0, or on a control input is open. An input lower than -3V on the RD are a Logic1, or on a control input is off. According to this standard, input logic electrical level between -3V and +3V have no definition
Noise tolerable limitation or voltage tolerable limitation is difference output voltage and input voltage. The big voltage undulation from RS-232 lead to a noise tolerable limitation wider than logic5TTL. For example, even thought a output from RS-232 driver is the smallest +5V,it’s also be weaken in the receiver or the noise peak rise to 2V, and still is a effective Logic0.Many outputs from RS-232 have the wider voltage undulation : ±9V and ±12V are very common affairs. All these affairs can lead to a noise limitation. The biggest permitting voltage undulation is ±15V, even though the receive must have no harm to deal with the voltage higher to ±25V.
The other two technical terms concern with RS-232 to be used is Mark and Space. Space is Logic0 and Mark is Logic1. These two technical terms which was used by the machine recording instrument to record binary data in many years ago, each of them are representation physical and blank.
Clocking Limitation:
TIA/EIA-232 including smallest and biggest clocking stipulate. All out the RS-232 interface chips all accord this stipulate.
Appointed revolving speed limited the biggest Potter rate of interface.
The revolving rate is measure to the rate of speed change when output cut-over voltage, and describe the change of instantaneous velocity in The advantage in limited the revolving is for improve signal quality by in the matter of fact to limited the problem which is due to voltage deflection, voltage deflection occur the signal in the long distance link which has high-speed rise and descend. There more detailed narrations to this problem are in capter10.
But revolving velocity also limited to the biggest speed of a link. Under speed of 30V/μs, a output need 0.3 μs to cut-over time in 166 times.
Actually, because the UART to read input data in near the middle of the digit, and also because many time’s consult clock in very accurate, usually can may use the digit width for cut-over time as short 5 to 10 time safety. Considered these conditions, some interface chips permitting 115kbps or more higher Potter rate, even though its infringe the suggestion this standard.
Except for has a biggest cut-over velocity, RS-232 driver also must according the lowest standard to ensure the signal no stopover in the undefined area between the logical condition. To control signal other 40bps and the lower signal. Signal lines must spend time not surpass 1μs in the transmit area between the effective Logic1 and Logic0.To other data and time signal this limitation place wide is 4% or under 20 bps is 2μs. Frequencies of signal rise and descend also probably close to be equal.
Transformation between 5V logical and RS-232
Many micro-controllers have asynchronous serial ports, but their input and output rather to use 5V logic than to RS-232 voltage. To link 5V logic to a RS-232 port need to transform into RS-232 electrical level and transform from RS-232 electrical level into 5V logic
To use of 5V logic, I supposed to the use of electrical level of TTL or CMOS logic chips, these chips are supply electricity by a single +5V electrical, signal electrical level refer to grounding electrical level. Tables 6-2 indicate this. I also supposed to positive logic, in here, the logical high electric level is logic1.
To TTL logic, a logical low output must below 0.4V, a logical low input must below 0.8V. A logical high output must be 2.4V at least and a logical high input must be 2V at least. To use of these logical electrical levels, an interface may have noise signal at 0.4V and not necessarily to make mistake.
These logical electrical levels are used into TTL logic of early days standard 7400 series and other drivers series, including 74LS 74F and 74AL STTL. The NMOS technology early is used to make micro---controllers also use these helical electrical levels.
Most CMOS chips definite different logical electrical levels and have wider noise tolerable. A logical low CMOS output below 0.1V and logical low input may higher to 20% electrical voltage, or to electrical voltage in 5V can reach to 1V. A logical high output to be 4.9V at least and logical high input must reach to electronically voltage’s 70% at least, or to 5V electrical input reach to 3.5V. To use of this series of logical electrical level, including 4000 series, 74HC and 74AC logic.
Some of CMOS chips have TTL compatible input and CMOS compatible output. Its make them can link with CMOS or TTL logic directly. The chips of follow to this usual practice including 74HC logic series and most of micro---controllers.