模式说明:The ui32Config parameter is the logical OR of three values: the number of data bits, the number of stop bits, and the parity. UART_CONFIG_WLEN_8, UART_CONFIG_WLEN_7, UART_CONFIG_WLEN_6, and UART_CONFIG_WLEN_5 select from eight to five data bits per byte (respectively). UART_CONFIG_STOP_ONE and UART_CONFIG_STOP_TWO select one or two stop bits (respectively). UART_CONFIG_PAR_NONE, UART_CONFIG_PAR_EVEN, UART_CONFIG_PAR_ODD, UART_CONFIG_PAR_ONE, and UART_CONFIG_PAR_ZERO select the parity mode (no parity bit, even parity bit, odd parity bit, parity bit always one, and parity bit always zero, respectively).
voidUARTIntHandler(void) { uint32_t ui32Status; ui32Status = UARTIntStatus(UART1_BASE, true); //get interrupt status UARTIntClear(UART1_BASE, ui32Status); //clear the asserted interrupts while(UARTCharsAvail(UART1_BASE)) //loop while there are chars { UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE)); //echo character GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED delay_ms(1); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED } }
intmain(void) { SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //使能外设 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //配置复用功能 GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); //分配UART信号 GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0|GPIO_PIN_1); //LED配置 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2 //串口参数设置 UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC); //使用16MHz内部高精度振荡器(PIOSC)作为UART模块时钟 UARTStdioConfig(1,115200, 16000000); //UART编号、波特率、UART时钟频率(频率要和上一行设的一致) //FIFO配置, UARTFIFOLevelSet(UART1_BASE,UART_FIFO_TX4_8,UART_FIFO_RX4_8); //FIFO填入半满(8byte)时触发中断 UARTFIFOEnable(UART1_BASE); //中断使能 IntMasterEnable(); //enable processor interrupts IntEnable(INT_UART1); //enable the UART interrupt UARTIntEnable(UART1_BASE, UART_INT_RX); //注册中断服务函数 UARTIntRegister(UART1_BASE,UARTIntHandler); UARTprintf("Enter Text: \n"); while (1) //let interrupt handler do the UART echo function { ; } }