才
学习LM3S系列,用LM3S8962写了一个
串口发送
数据的
程序,但是结果总是不对,请
高手分析分析。以下是代码和串口
调试助手的数据结果。
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "interrupt.h"
#include "sysctl.h"
#include "uart.h"
char buf[] = "hello world!
";
void delay(unsigned long ms)
{
while(ms--);
}
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
while(ulCount--)
{
UARTCharPut(UART0_BASE, *pucBuffer++);
}
}
void UART0_Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_1); //将PA0、PA1配置成UART模式
UARTConfigSet(UART0_BASE,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE));
UARTEnable(UART0_BASE);
}
void main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_8MHZ);//允许外部时钟作为
系统主时钟
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);
UART0_Init();
IntMasterEnable();
UARTIntEnable(UART0_BASE,UART_INT_TX);
//IntEnable(INT_UART0);
while(1)
{
UARTSend(buf,sizeof(buf));
UARTCharPut(UART0_BASE,'a');
long i = GPIOPinRead(GPIO_PORTF_BASE,0xff);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_2)^GPIO_PIN_2);
delay(120000);
i++;
/*i = UARTCharGet(UART0_BASE);
while(1)
{
while(!UARTCharsAvail(UART0_BASE))
{
UARTCharPut(UART0_BASE,UARTCharGet(UART0_BASE));
}
}
*/
}
}
串口调试助结果如下:
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
此帖出自
小平头技术问答
一周热门 更多>