Welcome to the Csdn-markdown Editor

Source: Internet
Author: User

Input/output Characters of serial port settings

s5pv210 UART Related Instructions
A universal asynchronous transceiver called the UART, Universal asynchronous RECEIVER and transmitter, is used to transmit serial data. When the data is sent, the CPU writes the parallel data Uart,uart in a certain format on a wire; When the data is received, the UART detects the signal of another wire, collects the serial in the buffer, and the CPU can read the UART to obtain the data.
In s5pv210, the UART provides 4 pairs of independent asynchronous serial I/O ports with 4 independent channels, each of which can operate in DMA mode or interrupt mode. Wherein, Channel 0 has a 256byte transmit FIFO and a 256byte receive FIFO, Channel 1 has a 64byte transmit FIFO and 64byte receive FIFO, while channels 2 and 3 have only 16byte of the send FIFO and 16byte receive FIFO.
The UART structure of the s5pv210 is shown below:

S5PV210 UART Structure diagram

The UART uses the standard Ttl/cmcos logic level to represent the data, in order to enhance the data anti-jamming ability and increase the transmission length, usually converts the Ttl/cmos logic level to the RS-232 logic level, views the schematic diagram to know mini210s uses the MAX3232SOP chip, The TX0 and DX0 are used:

Search "XuTXD0", you know:

By setting the UART-related registers, we can drive the UART to work to send and receive characters.
Example:

/main.c/
int main ()
{
char c;
Uart_init (); Initialize the serial port
while (1)
{
c = getc (); Receive a character C
PUTC (c+1); Send character c+1
}
return 0;
}
In the main function, Uart_init () is called first to initialize the UART, and then the character that is sent by the GETC is received by the PC, and then PUTC () is called back to the PC with the character +1.
/uart.c/
void Uart_init ()
{
1 configuration pin for rx/tx function
Gpa0con = 0x22222222;
Gpa1con = 0x2222;
2 setting data format, etc.
UFCON0 = 0x1; Enable FIFO
UMCON0 = 0x0; No flow control
ULCON0 = 0x3; Data bits: 8, no check, stop bit: 1
UCON0 = 0x5; Clock: PCLK, disable interrupt, enable UART to send, receive//3 set baud rate
UBRDIV0 = Uart_ubrdiv_val; 35
UDIVSLOT0 = Uart_udivslot_val; 0x1
}
The above code is a total of 3 steps, let's go to one by one to explain each step:
First step configuration pin for rx/tx function
Referring to the UART pin connection diagram, we need to set the Gpa0con and Gpa1con registers to enable the GPA0 and GPA1 pins for the UART function.

The second step is to set the data format, etc.
<1> ULCON0 to set the data format, see

Word Length = 11,8bit of data;
Number of Stop bit = 0,1bit;
Parity Mode = 000, no calibration;
Infrared mode = 0, using normal modes;
So ulcon0=0x3

<2> 9ucon0 is the UART configuration register, see

Receive mode = 01, using interrupt mode or polling mode;
Transmit mode = 01, using interrupt modes or polling mode;
Send break Signal = 0, normal transmission;
Loop-back mode = 0, do not use loopback mode;
We use polling to receive and send data without interruption, so bit[6-9] is 0;
Clock Selection = 0, using PCLK as the working clock of the UART;
We do not use DMA, so bit[16] and bit[20] are all 0;
So UCON0 = 0x5

<3> UFCON0 and UMCON0
These two registers are relatively simple, and the UFCON0 is used to enable Fifo,umcon0 to be used to set up no flow control.

The third step is to set the baud rate
Baud rate is the number of data bits transmitted per second, involving two registers: UBRDIV0 and UDIVSLOT0

Baud rate setting related formula: Ubrdivn + (num of 1 ' in Udivslotn)/16 = (PCLK/(bps x 16))? 1
wherein, by the maximum Operating Frequency for each sub-block figure, the UART works under PSYS, so pclk is Pclk_psys = 66.5MHz, our baud rate bps is set to 115200, so
(66.5mhz/(115200 x 16)) –1 = 35.08 = ubrdivn + (num of 1 ' s in Udivslotn)/16, so we set the ubrdiv0=35,udivslot0=0x1
The code for GETC () and PUTC () is as follows:
Receive one character
Char getc (void)
{
while ((UFSTAT0 & 0xff) = = 0); If the Rx FIFO is empty, wait for
return URXH0; Fetch data
}
Send a character
void Putc (char c)
{
while (UFSTAT0 & (1<<24)); If the TX FIFO is full, wait for
UTXH0 = C; Write Data
}


By reading the UTRSTAT0 Send/Receive status register, when receive buffer data ready= 1 o'clock instructions received data, read URXH0 Register can get 8bit of data; when transmitter empty = 1 o'clock description can send data, Write 8bit of data to UTXH0.

Welcome to the Csdn-markdown Editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.