ARM9 Hardware Interface Learning: UART

Publisher:GoldenDreamLatest update time:2013-01-04 Source: 维库开发网Keywords:ARM9  UART Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Before the introduction of UART, since there was no OS, after we wrote the program and burned it into the development board for execution, we could not print some prompt information during the program's running to tell us how the program was running or provide an interface for users to control the program's running path. In the end, we could only judge whether the program was executed successfully based on physical phenomena.

Using the serial port, we can send and receive the most basic data of the development board, interact with the development board, control the running of the program, and print out some information for debugging during the program running. In fact, the console of the bootloader and kernel (nfs mode) are both implemented through uart. From this we can see that uart is very important in actual development.

1. s3c2410 serial port basics

For detailed specifications of S3C2410A UART, please refer to the s3c2410 datasheet.

1) The default system clock used by the S3c2410 UART is PCLK.

This has to do with calculating the baud rate of the uart.

2) UART functional modules and data transmission process

Each uart consists of a baudrate generator, a transmitter, a receiver and a control unit.

The baud rate generator uses the PCLK (default) or UEXTCLK clock (mainly to achieve higher baud rates, the default PCLK is up to 230.4k bps). The transmitter and receiver each include a 16-byte FIFO and a data shifter. Data is sent and received through the transmit pin (TxDn) and the receive pin (RxDn).

When sending data, the CPU writes the data to be sent into the Transmit Buffer through the internal bus, which means that the programmer writes the data into the Transmit Holding Register (if the FIFO Mode is used, this register is also written, and the hardware will automatically determine it). Then the Transmitter moves the data in the Transmit Buffer into the Transmit Shifter according to the baud rate generated by the Buad-rate Generator, and finally sends it out through the TXDn pin.

When receiving data, the receiving pin (RxDn) receives data through the UART interface module at a certain baud rate, stores it in the Receive Shifter, and then moves it into the Receive Buffer. For programmers, the received data is read through the Receive Holding Register (similar to sending, whether or not FIFO Mode is used, the received data is obtained by reading this register).

Both the Transmit Holding Register and the Receive Holding Register are 8-bit registers, which means they can read and write one byte of data at a time.

3) Calculation of baud rate

The baud rate clock is mainly used to provide the clock signal required for sending and receiving serial port data.

The calculation method is the source clock (PCLK by default) divided by 16 and a 16-bit divisor. The divisor value is stored in the baudrate divisor register (UBRDIVn) and is specified by the user.

Usually we calculate the baud rate by calculating the divisor in reverse according to the desired baud rate, and then write the value into the Divisor Register (UBRDIVn). The formula is as follows:

UBRDIVn = (int) (PCLK/(bps x 16) ) -1

Bps is the baud rate we need to set, such as 115200.

2. s3c2410 serial port experiment

The experimental code is very simple and very suitable for getting started with serial port programming.

The content is: Print a line of information through the serial port to prompt the user to enter a character. If the user enters 'e', ​​the program will exit. If another character is entered, the program will try again.

The following is a detailed analysis: (Part of the content is quoted from "S3C2410 Complete Development Process", and I would like to thank the author for his contribution)

UART has 11x3 registers (3 UARTs). We choose the simplest method to conduct this experiment, and 8 registers are used. However, 5 registers are used for initialization, and the remaining 3 are used to receive and send data. In this way, operating UART is not complicated. This board uses UART0:

1) Initialization:

a. Define the used pins GPH2 and GPH3 as TXD0 and RXD0:

GPHCON |= 0xa0; //GPH2,GPH3 set as TXD0,RXD0

GPHUP = 0x0c; //GPH2, GPH3 internal pull-up

b.ULCON0 (UART channel 0 line control register): set to 0x03

This value means: 8 data bits, 1 stop bit, no parity, normal operation mode.

c.UCON0 (UART channel 0 control register): set to 0x05

Except for bit [3:0], all other bits use the default value. Bit [3:0] = 0b0101 means: both sending and receiving use "interrupt or query mode" - this experiment uses the query mode.

d.UFCON0 (UART channel 0 FIFO control register): set to 0x00

Each UART has a 16-byte transmit FIFO and receive FIFO, but this experiment does not use the FIFO and sets it to the default value of 0.

e.UMCON0 (UART channel 0 Modem control register): set to 0x00

This experiment does not use flow control, set the default value to 0

f.UBRDIV0 (R/W Baud rate divisor register 0): set to 27

UBRDIV0 = 27; //Baud rate is 115200

This experiment uses PLL, PCLK=50MHz, and sets the baud rate to 115200. The formula is:

UBRDIVn = (int) (PCLK / (bps x 16) ) -1

It can be calculated that UBRDIV0 = 27. Please use the error formula on page 314 of the S3C2410 data sheet to check whether this baud rate is within the tolerable error range. If not, you need to change to another baud rate (the 115200 used in this experiment is in compliance). [page]

2) Sending data:

a.UTRSTAT0 (UART channel 0 Tx/Rx status register):

Bit [2]: When there is no data to send, it is automatically set to 1. When we want to use the serial port to send data, we first read this bit to determine whether there is data occupying the sending port.

Bit [1]: Whether the transmit FIFO is empty. This bit is not used in this experiment.

Bit [0]: Whether there is data in the receive buffer. If so, this bit is set to 1. In this experiment, it is necessary to continuously query this bit to determine whether any data has been received.

b.UTXH0 (UART channel 0 transmit buffer register):

Write the data to be sent into this register.

3) Receiving data:

a.UTRSTAT0: As described above, we use [0]

b.URXH0 (UART channel 0 receive buffer register):

When the UTRSTAT0 bit [0] = 1 is queried, read this register to obtain the data received by the serial port.

4) Experimental source code

/* main.c */

#include "uart.h"

#include "clock.h"

#include "watchdog.h"

int Main(void)

{

char key = \' \';

clock_init(); //Initialize the clock

uart_init(); //Initialize the serial port

close_watchdog();

uart_send("uart communication success! ");

while(1)

{

uart_send("If you want to quit ,please pess \'e\' ");

key = uart_get();

if (key == \'e\')

{

uart_send ("you pressed \'e\' and you\'ll quit! ");

break;

}

else

{

uart_send("you pressed ");

uart_send(&key);

uart_send(",retry! ");

}

}

uart_send("the program exited by user! ");

return 0;

}

The following is the source code of the serial port related part:

void uart_init(void)

{

ULCON0 = 0x03; //8N1

UCON0 = 0x005; //Interrupt or query mode

UFCON0 = 0x00; //Do not use FIFO

UMCON0 = 0x00; //Do not use flow control

UBRDIV0 = 27; //Baud rate is 115200

GPHCON |= 0xa0; //GPH2,GPH3 set as TXD0,RXD0

GPHUP = 0x0c; //GPH2, GPH3 internal pull-up

}

void uart_send(char *c)

{

for (; *c != \'\\0\'; c++)

{

while (! (UTRSTAT0 & TXD0READY)); //Continue to query until data can be sent

UTXH0 = *c; //Send data

}

}

unsigned char uart_get(void)

{

while (! (UTRSTAT0 & RXD0READY)); //Continue to query until data is received

return URXH0; //Return received data

Keywords:ARM9  UART Reference address:ARM9 Hardware Interface Learning: UART

Previous article:Seismic acceleration signal processing system based on ARM and DSP
Next article:Design and implementation of motion controller based on ARM+FPGA

Recommended ReadingLatest update time:2024-11-16 15:53

Design of Remote Parameter Measurement Based on ARM Processor
     1 Introduction      Embedded systems have been developing rapidly due to their high cost-effectiveness and short development cycle. The development of various applications based on ARM processors is in full swing. Here we introduce a measurement and monitoring system based on the ARM9 embedded chip S3C2410. The
[Microcontroller]
Design of Remote Parameter Measurement Based on ARM Processor
cortex m0 lpc1114 serial uart query send and receive data
LPC1114 has a serial port with all the functional pins of a standard 9-pin serial port: RXD, TXD, RTS, CTS, DTR, DSR, DCD, IR Generally, we only use RXD and TXD. In this chapter, we will only introduce the use of RXD and TXD. Can be used for program downloads. You can set odd parity, even parity, or no parity. The dat
[Microcontroller]
cortex m0 lpc1114 serial uart query send and receive data
TQ2440 naked program: PC key test program for serial UART
  //=========================================   // NAME: main.c   // DESC: TQ2440 serial port UART test program   //=========================================      #include "def.h"   #include "option.h"   #include "2440addr.h"   #include   #include   #include   #include   #include   //============
[Microcontroller]
Mini2440 bare metal trial - DMA direct access to achieve Uart (serial port) communication
This can only be used as an opening chapter for your initial understanding of MDA Functionality:         Pass the string data to UTXH0 through DMA0 channel, and then         After the data is transferred, DMA0 generates an interrupt, a beep sound is heard, and the LED lights up.   DMA Basics The commonly u
[Microcontroller]
Mini2440 bare metal trial - DMA direct access to achieve Uart (serial port) communication
Design of palette display system based on ARM9 core S3C2410 chip and operating system
For a display device, the data update rate is proportional to the product of the number of pixels in the screen and the color depth. In an embedded Linux system, due to the constraints of processor resource configuration and computing power, when using a large resolution display (for example, on some terminals with la
[Microcontroller]
Design of palette display system based on ARM9 core S3C2410 chip and operating system
MCU AD receiving UART sending module circuit diagram PCB and vb host computer source code
The AD receiving UART transmitting module circuit schematic and PCB diagram drawn by Altium Designer are as follows: 【A brief description】 1. Dimensions: 50mm long x 25mm wide x 10mm high 2. Main chip: ATMEGA8 3. Working voltage: DC 5V II. Features: 1. Detection analog voltage range 0~5V 2. Digital tube display rang
[Microcontroller]
MCU AD receiving UART sending module circuit diagram PCB and vb host computer source code
UART-based data transmission and reception
UART (Universal Asynchronous Receiver and Transmitter) is a universal asynchronous receiver/transmitter. UART provides an RS-232C data interface. What is UART? UART is a universal serial data bus used for asynchronous communication. The bus is bidirectional and can achieve full-duplex transmission and reception. In
[Microcontroller]
Small Linux system production and transplantation based on linux-2.6.19 kernel
introduction The combination of ARM9S3C2410 microprocessor and Linux is becoming increasingly close, and is gradually being widely used in the embedded field. At present, the combination of S3C2410 and Linux can be seen in portable consumer electronics, wireless devices, automobiles, networks, storage products,
[Microcontroller]
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号