1. UART Principle
UART, Universal Asynchronous Receive Transmitter, is used to transmit serial data: when sending data, the CPU writes parallel data into UART, and UART sends it serially on one wire according to a certain format; when receiving data, UART detects the signal on another wire, collects the serial data in a buffer, and the CPU can read UART to obtain the data. UARTs transmit data in full-duplex mode, and the simplest connection method has only 3 wires, TxD is used to send data, RxD is used to receive data, and Gnd is used to provide reference levels for both parties.
UART uses standard TTL/CMOS logic levels to represent data. In order to enhance the data's anti-interference capability and increase data transmission length, the TTL/CMOS logic levels are usually converted to RS-232 logic levels, with 3~12V representing 0 and -3~-12V representing 1.
The TxD and RxD data lines transmit data in "bits" as the smallest unit. A frame is composed of several bits that have complete meaning and cannot be divided. It includes a start bit, a data bit, a check bit, and a stop bit. Before sending data, the UARTs need to agree on the data transmission rate (baud rate = 1/time per bit), the data transmission format (i.e., how many data bits there are, whether to use a check bit, whether it is odd or even, and how many stop bits there are).
Data transmission process:
(1) Normally the data line is in idle state (state 1).
(2) When sending data, the UART changes the state of the TxD data line (1->0) and maintains it for 1 bit time. When the receiver detects this start bit, it waits for 1.5 bits and then begins to detect the state of the data line one bit at a time to obtain the data.
(3) A UART frame can contain 5, 6, 7 or 8 bits of data. The sender changes the state of the data line one bit at a time and sends them out, sending the least significant bit first.
(4) If the check function is used, the UART will send a check bit after sending the data bit. There are two check methods: odd check and even check (is the number of "1"s in the data line plus the check bit equal to an odd number or an even number).
(5) Finally, a stop bit is sent and the data line returns to the idle state (state 1). There are three types of stop bit lengths: 1 bit, 1.5 bits, and 2 bits.
2. Features of S3C2440 UART
The UART function in S3C2440 has 3 channels, each of which can work in interrupt mode or DMA mode, that is, the UART can send an interrupt or DMA request to transfer data between the UART and the CPU. The UART consists of a baud rate generator, a transmitter, a receiver and control logic.
When using the system clock, the UART baud rate of S3C2440 can reach 115.2Kbit/s. If the external clock provided by the UEXTCLK pin is used, a higher baud rate can be achieved, and the baud rate can be controlled by programming. The FIFO depth of S3C2440's UART is 64. When sending data, the CPU first writes the data into the transmit FIFO, and then the UART automatically copies the data in the FIFO to the "Transmit Shifter". The transmit shifter inserts the data into the corresponding start bit, check bit, stop bit, etc. according to a certain format, and sends it to the TxDn data line one by one. When receiving, the receive shifter receives the data on the RxDn data line one by one, and then copies it to the receive FIFO, and the CPU can read the data from it.
Each channel of the S3C2440 UART supports 1 or 2 stop bits, 5, 6, 7 or 8 data bits, supports parity function, and also has infrared send/receive function.
3. Use of S3C2440 UART
Before using UART, you need to set the baud rate, transmission format, set the pin to UART function, and select the working mode of the UART channel as interrupt mode or DMA mode. After setting, write data to a register to send it, and read a register to get the received data. You can query the status register or set an interrupt to know whether the data has been sent or received.
1. Configure the registers of the corresponding I/O ports and set the UART channel pins involved to the UART function.
For example, in UART channel 0, GPH2 and GPH3 are used as TXD0 and RXD0 respectively. To use UART channel 0, first set the GPHCON register to set the GPH2 and GPH3 pin functions to TXD0 and RXD0.
2. UBRDIVn register, used to set the baud rate.
3. ULCONn register, set the transmission format.
4. UCONn register, used to select the UART clock source, set the UART interrupt mode, etc.
5. UFCONn register, UFSTATn register. The UFCONn register is used to set whether to use FIFO and set the trigger threshold of each FIFO. Each FIFO can be reset by adjusting the UFCONn register. By reading the UFSTATn register, you can know whether each FIFO is full and how much data is in it. If the FIFO is not used, the depth of the FIFO can be considered to be 1. If the FIFO is used, the FIFO depth of S3C2440 is 64.
6. UMCONn register, UMSTATn register, used for flow control.
7. The UTRSTATn register is used to indicate whether the data has been sent and whether the data has been received.
The configuration methods of the above registers can be found in the data sheet.
8. USERSTATn register is used to indicate the occurrence of various errors.
9. UTXHn register. When the CPU writes data to this register, the UART will save it into the buffer and send it out automatically.
10. URXHn register. When UART receives data, the CPU reads this register to obtain the data.
Previous article:ARM Notes: UART Program
Next article:ARM Study Notes---Serial Port
Recommended ReadingLatest update time:2024-11-16 19:29
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Shanghai Hangxin ACM32F070 development board + touch function evaluation board evaluation] + first look at the ACM32F070 development board
- [RVB2601 Creative Application Development] Dynamically load MBRE A fast implementation code of NTP with second-level accuracy
- Output waveform problem of integrator circuit
- Rockwell A4821 PMOS uC internal diagram
- ESP32-S2-Kaluga-1 Review Summary
- Some predictions about the national competition questions - about the quad
- Does anyone have a tutorial video on how to draw a PCB using Allegro? Can you share it?
- [NXP Rapid IoT Review] A Preliminary Study on Timer Functions
- What are thin AP, fat AP, AP+AC, and Mesh?
- Bluenrg_Why can't I add my own services or characteristics?