Hello World程序出问题了,高手解决下

[复制链接]
3590|9
 楼主| zheng522 发表于 2011-12-26 20:09 | 显示全部楼层 |阅读模式
本帖最后由 zheng522 于 2011-12-26 20:24 编辑

才学习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!\n";
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!
应该是ahello world!结果是这样子,不知道为什么,求高人指教下,分析分析。
kirayamato 发表于 2011-12-26 20:10 | 显示全部楼层
:shutup:what?
huigoushang 发表于 2011-12-26 21:03 | 显示全部楼层
你程序里的好多函数都木有见过啊
 楼主| zheng522 发表于 2011-12-26 23:12 | 显示全部楼层
不会吧,程序里的函数全都是API里的函数啊。
busicao85 发表于 2011-12-26 23:14 | 显示全部楼层
看不懂。。。
iEye 发表于 2011-12-27 09:59 | 显示全部楼层
1# zheng522
你的代码没有问题,我还实测了,一直发出ahello world! 你换个串口调试助手看看。
jzhjt29 发表于 2011-12-27 13:54 | 显示全部楼层
没问题啊
TI_MCU 发表于 2011-12-27 14:12 | 显示全部楼层
代码是没有问题的,如六楼所说,楼主可以换个调试环境~   用windows自带的超级终端也可以~

个人觉得串口助手经常出莫名其妙的错误
jamie-ma 发表于 2011-12-27 14:30 | 显示全部楼层
楼上说的对
tcwntc 发表于 2011-12-28 10:40 | 显示全部楼层
会不会是波特率设定的问题呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

74

主题

823

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部