当前位置: 代码迷 >> 嵌入开发 >> ARM板中UART一直出?的有关问题
  详细解决方案

ARM板中UART一直出?的有关问题

热度:8376   发布时间:2013-02-26 00:00:00.0
求助ARM板中UART一直出?的问题。
各位大侠,小弟最近刚开始学习ARM,是用ADS在裸机上调。仿照学习板上的程序(基本是拷贝)编写了一个串口发送数据的程序,最后用超级终端来调试。发现没按照既定内容输出,输出几个空格之后就输出一个问号“?”(?? ? ? ?? ????? ??? ?? ???
??????? ?? ? ???? ???? ????? ? ????? ? ? ?? ?
??????? ?? ? ????????? ???? ???? ???? ?????
 ? ????? ?? ?? ??????????? ??????????)求解。
程序:


#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>  
#include "inc\44b.h"
#include "inc\option.h"
void Delay(unsigned int);
void Uart_init(int,int);
void Uart_SendByte(int);
void Uart_Printf(char *fmt,...);
void Uart_SendString(char *pt);
void Main(void)
{
Uart_init(0,115200);
rPCONC =0xffff5555; //select all the port of GPC as output;
rPUPC = 0x0000;
while(rUMSTAT0&0x01)
{
  Uart_Printf("[UART IrDA Rx Test]\n");
  rPDATC =0x0000; //指示灯
Delay(10);
  Uart_Printf("This test should be configured two boards.\n");
  rPDATC =0x000a;//指示灯
  Delay(10);
  Uart_Printf("Press any key to start Rx and then Start Tx....\n");
  Delay(10);
rPDATC =0x0003;//指示灯
}
}
void Delay(unsigned int x)
{
unsigned int i,j,k;
for(i=0;i<x;i++)
for(j=0;j<0xff;j++)
for(k=0;k<0xff;k++);
}
void Uart_init(int mclk,int baud)
{
  int i;
  if(mclk==0)
mclk=MCLK;
  rUFCON0=0x0; //FIFO disable
  rUFCON1=0x0;
  rUMCON0=0x0;//自发自收控制
  rUMCON1=0x0;
//UART0
  rULCON0=0x3; //Normal,No parity,1 stop,8 bit
// rULCON0=0x7; //Normal,No parity,2 stop,8 bit
  rUCON0=0x245; //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
  rUBRDIV0=( (int)(mclk/16./baud + 0.5) -1 );
//UART1
// rULCON1=0x7; //Normal,No parity,2 stop,8 bit
  rULCON1=0x3;
  rUCON1=0x245;
  rUBRDIV1=( (int)(mclk/16./baud + 0.5) -1 );

  for(i=0;i<100;i++);
}
void Uart_SendByte(int data)
{
  if(data=='\n')
{
while(!(rUTRSTAT0 & 0x2));
Delay(10); //because the slow response of hyper_terminal 
WrUTXH0('\r');
}
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH0(data);
 }
 void Uart_SendString(char *pt)
{
  while(*pt)
Uart_SendByte(*pt++);
}
void Uart_Printf(char *fmt,...) //可变参数宏
{
  va_list ap;
  char string[256];
  va_start(ap,fmt);
  vsprintf(string,fmt,ap);
  Uart_SendString(string);
  va_end(ap);
}

------解决方案--------------------------------------------------------
串口连到PC机测试的?两边的波特率要设置相同,换一个“串口调试助手”试试。
------解决方案--------------------------------------------------------
波特率,多试几个,比较常用的有115200,38400等