AI For DIY

Thursday, September 1, 2022

UART Communication

1. About UART communication

If there is a basis for all systems, UART(Universal Asynchronous Receiver and Transmitter) is the basis for communication. Early development, in the 1960s, different companies used the same function under different names, but settled under this name in the 1970s. As the name suggests, it is used in many places and is asynchronous full-duplex communication. Let's take a closer look at this UART communication.

 

2. UART communication wiring diagram

 

As shown in the figure, the wiring diagram of UART communication consists of the transmission line from TX to RX and the reference line (GND). The transmitting device and the receiving device are always one, 1:1 communication. When two devices set the communication speed and data structure in advance and transmit according to this, the receiving side checks whether the speed and structure match and accepts the data. The speed supported by this communication is not fixed, and although it is not unreasonable at 1 Mbps or less, it is usually according to the requirements of the other device.
  However, if the error rate is too high depending on the reference clock to be set, normal operation may not be possible, so it is necessary to check in advance. It is more accurate to oscillate the reference clock with a dedicated device such as a crystal, so if you use it for a long time, it is better to use a dedicated device rather than an RC oscillator. In addition, I personally recommend not to use it if the error rate between the frequency divided by the clock and the communication speed is 2% or more.

 

3. UART communication data frame

 

The data frame can be divided into 5 sections as shown in the figure. It has a value of logic '1' as the idle state in the state of not communicating. Thereafter, data is transmitted starting with the start bit having a value of '0' in the meaning of starting communication. And if necessary, a parity bit may be added, and it ends with a stop bit having a value of '1' at the end. If there is no additional communication, the standby state of '1' continues as it is, and if there is communication, it continues with the start bit having a value of '0'.
  Among them, data is information that is actually transmitted and can be set to one of 4, 5, 6, 7, or 8 bits as needed, and is transmitted from the least significant bit. In the case of parity bits, either even parity or odd parity must be selected, and the calculation range is determined by the operation result for the entire data. If there is no parity (None), it is removed from the data frame and only the start, data, and stop bits remain. The last stop bit determines the length of '0' by selecting one of 1, 1.5, and 2 bits as needed.
  The most frequently used setting is '8 data bits, no parity, 1 stop bit', abbreviated as '8-N-1'. For example, if ‘A’ and ‘B’ (ASCII) are transmitted through continuous communication in the ‘8-N-1’ structure, it is as follows.

 

 

4. UART reception

The UART receiver is slightly different for each product, check the received state by using the internal high-frequency clock that is 8 times(Baud×8) or 16 times(Baud×16) higher than the set communication speed. That is, 8 MHz or 16 MHz is required inside the transceiver to carry out communication of 1 Mpbs. In other words, the internal clock of the receiver is used to check data and the communication speed is determined by dividing the clock, which is the cause of the limitation on the maximum speed.

 

 

As shown in the figure, based on the falling edge of the start bit, the values ​​of three clock points are read at the half position of the clock multiplier (1/2 position of the bit). That is, when it is 16 times, it reads the 7th, 8th, and 9th values ​​(3rd, 4th, and 5th times if it is 8 times), and two or more logics among these 3 results are recognized as signals.
  If it reads from the middle of the start bit and does not recognize it as '0', it is judged that the start bit is misunderstood and waits until the falling edge of the start bit again. Then, data reception is also read from the 23, 24, and 25th half positions of the first data in the same way as the start bit, two or more logics are read as values, and the same method is repeated until the data ends. Similarly, if it is checked in the middle of the stop bit, but it is not recognized as ‘1’, the data frame is treated as an error. That is, when '8-N-1', the internal 16 times clock, the stop bit '1' must be recognized at the 143, 144, and 145th clocks from the point of recognizing the start bit '0'. If it is not recognized, it is an error.(151, 152, 153th from the falling edge of the start bit)
  Because of this reception problem, it is better to match the speed determined when the clock is divided by the transmitter. However, since it cannot always match in the environment, the error is checked. This is called the error rate and is calculated as follows.

 

((BaudCLK×PRS)÷ Baud)×100 [Baud: Baud rate (bps), CLK: Internal clock (Hz), PRS: Division ratio]

 

If this error exceeds 5% in ‘8-N-1’, 16 times standard, it is highly likely that it will not work.

 

5. USART Communication

 

If UART was asynchronous communication, it was changed to synchronous communication by adding a clock line to it, and the name is called USRT (Universal Synchronous Receiver and Transmitter). When the receiver recognizes it, it recognizes it according to the received clock, so there is no need for an internal high-frequency clock. The error rate due to division is eliminated and the communication speed is improved, so it can operate at over 10 Mbps. However, since the clock has to be managed in one device, the other side waits for transmission until the clock arrives. At this time, the side that transmits the clock and requests transmission is called the master or the controller, and the side that receives the clock and sends it as a response is called the slave or target.
  Although it has the advantage of increasing speed, it is rarely used compared to UART, because that speed is not required or most products do not support USRT. In addition, since data is judged based on the clock, the start bit and stop bit are unnecessary, but there is an unreasonable need to remain in accordance with the data frame.
  Nevertheless, it is rarely used, so manufacturers combine the two so that it can be used as both a UART and a USRT, and this is called USART (Universal Synchronous/Asynchronous Receiver and Transmitter).

 

6. Conclusion

UART communication is often used when switching to external wired communication or wireless communication, so be sure to understand it.

No comments:

Post a Comment