UART is a chip used to control computers and serial devices. One thing to note is that it provides an interface to the data terminal device so that the computer can communicate with the modem or other serial devices that use the RS-232C interface. As part of the interface, UART also provides the following functions:
- Converts parallel data transmitted from within the computer to the output serial data stream;
- Converts serial data from outside the computer into bytes for use by devices that use parallel data inside the computer;
- Add the parity bit to the output serial data stream and perform the parity check on the data streams received from the outside;
- Add the start and stop mark to the output data stream and delete the start and stop mark from the received data stream;
- Handle the interrupt signal sent by the keyboard or mouse (the keyboard and mouse pass are also serial devices );
- It can manage the synchronization between computers and external serial devices;
The asynchronous serial communication protocol is used to transmit each character of data in a serial mode. For example:
The meaning of each bit is as follows:
Start position: first sends a signal with the logic "0", indicating the start of the transmission character.
Data bit: followed by the start bit. The number of data bits can be 4, 5, 6, 7, 8, and so on. Generally, ASCII code is used. The transfer starts from the second BIT and is located by the clock.
Parity bit: After the data bit is added (following the end of the Data bit), the number of "1" digits should be an even number (even verification) or an odd number (odd verification ), to verify the correctness of data transmission.
Stop bit: it is the end sign of a character data. It can be 1-bit, 1.5-bit, or 2-bit high (logical "1 ").
Idle bit: In the logical "1" status, indicating that no data is transferred on the current line.
Baud Rate: a pointer to the data transmission rate. The number of bits transmitted per second ). For example, if the data transfer rate is 120 characters/second and each character is 10 characters, the Transmission baud rate is:
10 × 120 = 1200 characters/second = 1200 Potter.
The preceding data bit, parity bit, and baud rate can all be set on the COM interface. You can alsoCodeSet the UART register. The meanings of the UART register are as follows:
Below are a few smallProgramTo understand the data transmission process of UART communication protocol:
# Include "2410lib. H "/************************************* **************************************** * ***************** Name: uart0_test * FUNC: UART test function * para: none * RET: none * modify: * Comment: **************************************** **************************************** * ************/void uart0_test () {char cinput [256]; uint8t ucinno = 0; char C; uart_init (, 0); // define the baud rateuart_pri Ntf ("\ n uart0 communication test example \ n"); uart_printf ("Please input words, then press Enter: \ n"); # ifdef boardtestsprintf (& cinput, "Type via uart0 to test. "); print_ LCD (195,170, 0x1c, & cinput); # endifuart_printf (" "); g_nkeypress = 1; while (g_nkeypress = 1) // only for board test to exit {c = uart_getch (); // uart_sendbyte (c); uart_printf ("% C", c); If (C! = '\ R') cinput [ucinno ++] = C; else {cinput [ucinno] =' \ 0'; break ;}} delay (1000 ); uart_printf ("\ nthe words that you input are: % s \ n", cinput); uart_printf ("end. \ n ");} void main (INT argc, char ** argv) {sys_init (); // initial S3C2410's clock, MMU, interrupt, port and UART while (1) {uart0_test () ;}for (;;);}
here we use the uart_init function to complete the settings of each bit of UART. Now let's take a look at how uart_init is defined in the system:
Void uart_init (INT nmainclk, int nbaud, int nchannel) {int I; If (nmainclk = 0) nmainclk = pclk; Switch (nchannel) {Case uart0: rufcon0 = 0x0; // UART channel 0 FIFO control register, FIFO disablerumcon0 = 0x0; // UART chaneel 0 modem control register, AFC disablerulcon0 = 0x3; // line control register: normal, no parity, 1 stop, 8 bits // [10] [9] [8] [7] [6] [5] [4] [3: 2] [1:0] // clock Sel, TX int, RX int, RX time out, RX err, loop-back, send break, transmit mode, receive mode // 0 1 0, 0 1 0, 01 01 // pclk Level Pulse disable generate normal interrupt or pollingrucon0 = 0x245; // control register // rubrdiv0 = (INT) (nmainclk/16. /nbaud)-1); // baud rate divisior register 0rubrdiv0 = (INT) (nmainclk/16. /nbaud + 0.5)-1); // baud rate divisior register 0 break; Case uart1: rufcon1 = 0x0; // UART Channel 1 FIFO control register, FIFO disablerumcon1 = 0x0; // UART chaneel 1 modem control register, AFC disablerulcon1 = 0x3; rucon1 = 0x245; rubrdiv1 = (INT) (nmainclk/16. /nbaud)-1); break; Case uart2: rulcon2 = 0x3; rucon2 = 0x245; rubrdiv2 = (INT) (nmainclk/16. /nbaud)-1); rufcon2 = 0x0; // UART Channel 2 FIFO control register, FIFO disablebreak; default: break;} for (I = 0; I <100; I ++); delay (0 );}
Uart0 --- uart2 is the three registers provided by the development board. You can set UART registers by assigning values on the pins such as rufcon, rumcon, rulcon, rucon, and rubrdiv.
For more information about the source code of the arm Development Board, you cannot upload or share resources due to an exception on the csdn Resource Sharing page. If you need it, leave a message to me and I will send it to you.
"Things often change people, but people cannot change things ." So, why not change yourself first?
Tomorrow, continue learning!