ARM Notes: UART Learning Notes

Publisher:会弹琴的鲸鱼3312Latest update time:2017-11-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Reference address:ARM Notes: UART Learning Notes

Previous article:ARM Notes: UART Program
Next article:ARM Study Notes---Serial Port

Recommended ReadingLatest update time:2024-11-16 19:29

MSP430Ware Study Notes UART ACLK 9600-8-N-1
1. Before initializing UART0, you need to initialize ACLK, SMCLK and MCLK. In the sample code, XT1 is used, ACLK is 32768, and SMCLK and MCLK are about 8MHZ. 2. The UART clock can refer to ACLK or SMCLK. In this example, ACLK is used. Since the ACLK clock is used, the serial port rate cannot exceed 32768. 9600 is a mo
[Microcontroller]
s3c2440 learning path-008 uart implements printf function
1. Basic principles Because the program is currently in the bare board stage, it can only output strings, and there is no C language printf function to call. However, when debugging the program, I want to call printf to debug like C language, so I can only implement it myself. In C language, the prototype of the pri
[Microcontroller]
s3c2440 learning path-008 uart implements printf function
UART extension implementation designed for C8051F310
   As a simple data sending protocol, the UART data sending protocol is widely used in the data transmission of various current digital peripherals. However, current PCs have the problem of no UART interface or fewer interfaces. When a PC needs to be used to handle multiple digital devices simultaneously, UART expansi
[Microcontroller]
UART extension implementation designed for C8051F310
UART serial port operation of Tiny210 bare metal
start.S source code: .global _start _start:     ldr sp, =0xD0030000 @Initialize stack     b main ==================================================================== main.c: #include "clock.h" #include "led.h" #include "uart.h" #include "lib.h" int main(void) {     led_init(); // Set the corresponding pin to output   
[Microcontroller]
STM8 Universal Asynchronous Receiver/Transmitter (UART)
STM8 UART Introduction The universal synchronous asynchronous receiver/transmitter (UART1, UART2 or UART3) of the STM8S microcontroller family provides a flexible method for full-duplex data exchange with external devices using the industry standard NRZ asynchronous serial data format. The STM8 UART provides a wide ra
[Microcontroller]
STM8 Universal Asynchronous Receiver/Transmitter (UART)
MAX3108 SPI UART with FIFO
The small-footprint MAX3108 universal asynchronous receiver-transmitter (UART) with 128-word receive and transmit FIFOs each is controlled via a serial I²C or SPI™ controller interface. Automatic sleep and shutdown modes help reduce power consumption during periods of inactivity. The low 500μA (max) supply curr
[Analog Electronics]
MAX3108 SPI UART with FIFO
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号