void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
bool staus=true;
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
staus=UARTCharPutNonBlocking(UART2_BASE, *pui8Buffer++);
}
if(staus)
{
LED_Blink(GREEN);
}
else
{
LED_Blink(RED);
}
}
void
ConfigureUART(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
GPIOPinConfigure(GPIO_PD6_U2RX);//ÅäÖÃÄÚÉè¹Ü½ÅÓ³Éä
GPIOPinConfigure(GPIO_PD7_U2TX);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);//¹Ü½ÅÅäÖÃΪ´®¿ÚËùÐ蹦ÄÜ
//
// Use the internal 16MHz oscillator as the UART clock source.
//
//UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//UARTClockSourceSet(UART0_BASE, UART_CLOCK_SYSTEM);
UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
}
int main(void)
{
//SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);//ƵÂÊ=400/2/4=50M
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);//ƵÂÊ=400/2/2.5=80M
//ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //16M
PORT_Configuration
ConfigureUART();
//GPIOIntTypeSet(KEY_PORT_BASE, ALL_KEY, GPIO_LOW_LEVEL);
//GPIOPinIntEnable(KEY_PORT_BASE, ALL_KEY);
//IntEnable(INT_GPIOF);
for (; ; )
{
if(KEY_LEFT==ROM_GPIOPinRead(KEY_PORT_BASE, ALL_KEY))
UARTSend((uint8_t *)"what fuck !!", 12);
else
{if(KEY_RIGHT==ROM_GPIOPinRead(KEY_PORT_BASE, ALL_KEY))
UARTSend((uint8_t *)"and you ? !!", 12);
else
LED_Blink(BLUE);
}
}
}
UARTO 有用,移植到 UART2 就不行了;求建议。 下面调试成功的代码。
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
bool staus=true;
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
staus=UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
if(staus)
{
LED_Blink(GREEN);
}
else
{
LED_Blink(RED);
}
}
void
ConfigureUART(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);//配置内设管脚映射
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);//管脚配置为串口所需功能
//
// Use the internal 16MHz oscillator as the UART clock source.
//
//UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//UARTClockSourceSet(UART0_BASE, UART_CLOCK_SYSTEM);
UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
}
int main(void)
{
//SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);//频率=400/2/4=50M
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);//频率=400/2/2.5=80M
//ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //16M
PORT_Configuration
ConfigureUART();
//GPIOIntTypeSet(KEY_PORT_BASE, ALL_KEY, GPIO_LOW_LEVEL);
//GPIOPinIntEnable(KEY_PORT_BASE, ALL_KEY);
//IntEnable(INT_GPIOF);
for (; ; )
{
if(KEY_LEFT==ROM_GPIOPinRead(KEY_PORT_BASE, ALL_KEY))
UARTSend((uint8_t *)"what fuck !!", 12);
else
{if(KEY_RIGHT==ROM_GPIOPinRead(KEY_PORT_BASE, ALL_KEY))
UARTSend((uint8_t *)"and you ? !!", 12);
else
LED_Blink(GREEN);
}
}
}
|