简介 / Introduction
UART 流量控制是一种让慢速和快速设备通过 UART 相互通信而不会丢失数据的方法。
考虑两个设备通过 UART 通信的情况。发送器 T 正在向接收器 R 发送一长串字节。R 是一个比 T 慢的设备,在某些时候 R 无法跟上。它需要对数据进行一些处理或清空一些缓冲区,然后才能继续接收数据。
R 需要告诉 T 暂时停止传输。这就是流量控制的作用。 流量控制提供额外的信令,通知发送器应该停止(暂停)或开始(恢复)传输。
目前存在几种形式的流量控制。例如,硬件流量控制使用额外的导线,这些导线上的逻辑电平决定发送器是继续发送数据还是停止发送。在软件流量控制中,通过正常数据线发送特殊字符来启动或停止传输。
UART Flow Control is a method for slow and fast devices to communicate with each other over UART without the risk of losing data.
Consider the case where two units are communicating over UART. A transmitter T is sending a long stream of bytes to a receiver R. R is a slower device than T, and at some point R cannot keep up. It needs to either do some processing on the data or empty some buffers before it can keep receiving data.
R needs to tell T to stop transmitting for a while. This is where flow control comes in. Flow control provides extra signaling to inform the transmitter that it should stop (pause) or start (resume) the transmission.
Several forms of flow control exist. For example, hardware flow control uses extra wires, where the logic level on these wires define whether the transmitter should keep sending data or stop. With software flow control, special characters are sent over the normal data lines to start or stop the transmission.
流控协议 / Flow Control Protocols
下面来介绍实现流控的常用方法。
-
UART Hardware Flow Control / 硬件流控
使用硬件流量控制(也称为 RTS/CTS 流量控制)时,除了数据线外,还需要两条额外的导线。它们分别称为 RTS(请求发送)和 CTS(清除发送)。这两条线在两台设备之间交叉耦合,因此一