Reprinted please indicate from: http://blog.csdn.net/icyfox_bupt/article/details/6766830
Baidu Encyclopedia: UART: Universal asynchronous transmitter/transmitter, a general asynchronous receiving/sending device. UART is a parallel input into a Serial Output chip, usually integrated on the motherboard, most of which are 16550afn chips.
Lm3s series single-chip microcomputer generally have UART input and output functions. For lm3s811 single-chip microcomputer, it has two UART ports: uart0 and uart1, the type of this interface is the comport used on our computer. Note that the single-chip microcomputer does not provide UART independent pins, so uart0 uses the pin gpioa 0 \ 1 uart1 uses the pin gpiod 2 \ 3, and, because I use a notebook without a comport, I still need a com2usb adapter.
Let's take a look at the program:
First, the header file: This time added the # include "driverlib/UART. H", that is, the UART driver library.
In pin settings, you must enable the gpio port on the peripheral device: sysctlperipheralenable (sysctl_periph_uart0 );
The next step is to configure the UART frame format: the number of data records per frame, whether there are any checked bits, and whether there are other settings, as shown in the following code:
Uartconfigsetexpclk (uart0_base, sysctlclockget (), 115200, percent | uart_config_par_none | percent); // configure uart0, set the frame format to 8-bit data, 1-bit stop bit, no parity, the baud rate is 115200
I believe you can read this configuration by yourself.
As mentioned in a few important points, we can check the Code directly:
# Include "INC/hw_types.h" # include "INC/hw_memmap.h" # include "driverlib/sysctl. H "# include" driverlib/gpio. H "# include" driverlib/UART. H "// note that this is the newly added header file void uartsendstring (unsigned long ulbase, char * pcbuf); // send the string (this is a function written by myself) int main () {char C; sysctlclockset (sysctl_osc_main | week | sysctl_sysdiv_1); hour (week); gpiopintypeuart (gpio_porta_base, gpio_pin_0 | gpio_pin_1 ); // set the pin type to bytes (bytes); // provides the system clock uartconfigsetexpclk (uart0_base, sysctlclockget (), 115200, role | uart_config_par_none | uart_config_stop_one) for uart0 ); // configure uart0, set the frame format to 8-bit data, 1-bit stop bit, no parity check, the baud rate is 115200 uartenable (uart0_base); // enable uart0uartsendstring (uart0_base, "Hello World"); // send the string "Hello World" uartcharput (uart0_base, 10); // line feed. This function is the original function and can only send the ASCII code uartcharput (uart0_base, 13); While (1) // The while code function is to output the characters entered by the computer {c = uartcharget (uart0_base); // receives a character uartcharput (uart0_base, c); // send the received characters} void uartsendstring (unsigned long ulbase, char * pcbuf) {While (* pcbuf) {uartcharput (ulbase, * pcbuf ++ );}}
This is the usage of some functions in UART. If you want to use uart1, you must change the above-enabled gpioa 0 \ 1 to gpiod 2 \ 3 and change all uart0 to uart1.
After the program is written, what does the computer use to accept it? We recommend the Super Terminal and serial port debugging Assistant Software.
A Brief Introduction to the Super Terminal:
The Super Terminal Program is very small, but it has powerful functions in serial transmission. Connect the computer to the microcontroller using the serial port, open the Super Terminal, start a name at will, next, select the comport, generally only one available, then the next step is to set, select the rate, stop bit, check bit, and set the hardware to "NONE", you can use it.
Super Terminal download http://download.csdn.net/detail/icyfox_bupt/3591890
If you have any questions, please comment. Thank you.