author: lunar
date: Sun 27 Sep 2020 07:57:23 AM CST
USART Serial Communication
USART: Universal Synchronization Asynchronization Receive Trigger.
- Simplex: Information can only transfered from source to destination.
- Half Duplex: Both-way communication, but both parties cannot transmit information at the same time.
- Full Duplex: Both-way communication, and simultaneous communication is allowed.
USART Features
- Use the DMA method of multi-buffer configuration to realize high-speed data communicationFull duplex, asynchronous communication.
- NRZ standard format.
- Fractional baud rate generator.
- Programmable word length(8 bits or 9 bits)
Baud Rate
Baud rate represents the number of symbol symbols transmitted per second. It is a measure of symbol transmission rate. It is expressed by the number of times the carrier modulation state changes per unit time. 1 baud means 1 transmission per second Symbols.
Difference between bit rate and baud rate
bit rate = baud rate * (binary digits response to a single modulation state)
Word length settings
start bit: low level
end bit: high level
rising time: time spent on rising to 90% of high level from the low level.
Flow Control and Hand Shaking
In serial communication, if sender and receiver use asynchronous communication method and both sides do not share clock signal, it's necessary to carefully consider how to coordinate the pace of communication parties, to avoid the data loss or data overflow at the receiving end due to the sending end sending too fast. Especially before the receiver process the data in the USART hardware buffer, the sender must be prohibited for sending new data, this process is called Flow Control and flow control can be achieved with the aid of Hand Shaking mechanism.
RS232 interface supports no hand shaking、hardware hand shaking and software hand shaking three approaches.
No Hand Shaking requires the sending and receiving parties to set the same transmission rate in advance, generally only low-speed transmission can be achieved. At the same time, the hardware designs need precise clock division, because the receiver must strictly determine the time of data sampling, otherwise data reception error can be easily caused, the higher the transmission rate, the more obvious. In various embedded systems based on MCU, because the internal working clock of the serial port module come from the frequency division of the independent clock signal, and the frequency division is often not accurate enough, improper frequency division settings often lead to higher data error rates. In principle, it is hoped that the frequency division and the serial port can be accurately match the transmission rate, which is often independent of the speed.
Hardware Hand Shaking requires "Request Transmission Send"(RST) and "Clear Transmission Send"(CST) two signals. The sender sets RTS valid to notify the receiver to prepare for receiving before sending data. And the receiver sets the CTS valid after getting prepared, as a notification to the sender that the receiver is prepared for receiving data and waits for the data. The sender must wait for the receiver's CTS signal to actually start data transmission. In this way, the sender and the receiver form an interlocking mechanism, which ensure that the sender will not send at a rate exceeding the receiver's ability to cause the receiver to overflow.
Frame division and frame grouping
Error detect and CRC check
Flow control solves the problem of speed or pace matching between communication parties, but does not solve the problem of transmission errors.