Technology Sharing

UART serial communication experiment

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Communication Types

1.1 According to the data communication method

1.1.1 Serial Communication

advantage:Occupies fewer pins and has a low cost

shortcoming: Slow transmission speed

ApplicationsLong distance, low rate communication occasions

1.1.2 Parallel Communication

advantage: Fast transmission rate

shortcoming:Occupies many pins and has high cost

Applications: Short distance occasions.

1.2 According to the data transmission direction

1.2.1 Simplex Communication:

      Data can only be transferred in one direction.

1.2.2 Half-duplex communication:

Data can be transferred in both directions, but the transfer is time-sharing.

1.2.3 Full-duplex communication:

Data can be transmitted in both directions simultaneously.

1.3 Classification by data synchronization direction

1.3.1 Synchronous Communication

Data transmission with clock port

1.3.2 Asynchronous Communication

There is no clock port, and the sender and receiver use their own clocks to control the data transmission and reception process.

2.UART serial port

Meaning: Universal Asynchronous Receiver/Transmitter, a serial data bus,It converts parallel data into serial data for transmission when sending data, and converts received serial data into parallel data when receiving data. Two signal lines are required to achieve this, one for serial port transmission and the other for serial port reception. The TXD and RXD between the two devices must be cross-connected.

1.Physical Layer: Interface type, level standard, etc.

2.Protocol Layer: Communication protocol (including data format, transmission rate, etc.)

         UART During the sending or receiving process, a frame of data is composed of 4 Parts: start bit, data bit, parity bit and stop bit 。

        Start bit: At the beginning of a frame, a low bit must be kept at a low level of 0.

        Data bits: The data bits to be transmitted, the data bits can be selected from 5 to 8 bits, with LSB in front and MSB in the back.

        Check Digit: Optional bit, occupies one bit, and can also be without check.

        Stop bits: The end of a frame, required, optional, occupies 0.5/1/1.5/2 bits, maintains a logic high level.

Baud rate: The speed of serial communication is expressed in baud rate, which indicates the number of bits of binary data transmitted per second. The unit is bps (bits per second).Common baud rates are 96001920038400, 57600 and 115200 wait.

UART is responsible for completing the serial-to-parallel conversion of data, while the signal transmission is realized by the external driver circuit. The transmission process of electrical signals has different level standards and interface specifications.Interface standardsRS232RS422, RS485, etc., which define different electrical characteristics of the interface, such as RS-232 is a single-ended input and output, and RS-422/485 Differential input and output

wait.

3. Experimental tasks

        The task of this experiment is to send data from the host computer to the Venusstar development board through the serial port debugging assistant. The end receives data through the USB_UART serial port and sends the received data to the host computer to complete the serial port data loopback. UART baud rate: 115200. Stop bit: 1, data bit 8, no parity bit.

4. Draw a system block diagram

In the uart_rx module: uart_rxd is the data received by the serial port, uart_rx_done indicates that the data conversion is completed (the data is converted from parallel data to serial data). uart_rx_data indicates the serial data after the conversion. Note: The received parallel data is 1 bit, and the converted serial data is 8 bits.

In the uart_tx module: uart_tx_dat indicates the 8-bit serial data that has been converted, uart_tx_en indicates that the data has been converted from parallel to serial, uart_txd indicates the parallel data after conversion, and uart_tx_busy indicates that the data is being converted from serial to parallel.

       

5. Draw a waveform graph

Because uart_rxd is an asynchronous signal and the start bit is low level, it is necessary to capture the falling edge change here, so it needs to be processed three times, so that the data receiving start bit signal can be obtainedstart_enThe signal indicates that parallel data is coming, and the parallel-to-serial conversion can be performed next;

                  rx_flagIndicates that the parallel data to serial data conversion is in progress, starting from start_en and ending when rx_cnt = 9 and baud_cnt reaches 216. This is to avoid the situation where the start bit of the next frame data comes before the end of the current frame data, so the stop bit is controlled at 0.5 bits;

                 baud_cnt:The system clock is 50Mhz, that is, 50000000, and the baud rate here is 115200, so 50000000/115200=434, that is, it takes 434 system clock cycles to transmit one bit of data, so the baud_cnt counter is needed.

                 rx_data:Because the serial data is 8 bits, it is better to add an index to facilitate finding a certain bit of data and assigning values. Therefore, rx_cnt is needed.

                 rx_data_t: Converted serial data.

uart_rx waveform

uart_tx_en: indicates that the serial data conversion is completed, that is, the uart_rx_done signal.

uart_data_t: Temporarily stores the converted serial data bits for subsequent transmission.

baud_cnt: Same as above.

tx_cnt: Same as above.

uart_tx waveform

6. Simulation

uart_rx simulation waveform

uart_tx waveform simulation

uart overall waveform

7. Board-level verification

Open the serial port debugging tool

Add debug attributes to the signals that need to be debugged, burn the program to the development board, and enter the following information in the serial port assistant.

Because the four-digit hexadecimal codes of 55 66 77 are 0101 0101, 0110 0110, 0111 0111.