ys123 发表于 2012-9-13 16:45:24

请求大侠帮忙,为什么这个程序下进去串口调试工具接不到

大侠帮忙看一下为什么这个程序下进msp430g2553中从超声波传感器接不到数据?串口调试工具接收部分无显示
#include"msp430g2553.h"

unsigned int a=0;

void UartRegCfg()
{
UCA0CTL1 |=UCSWRST;      //reset UART module,as well as enable UART module
UCA0CTL1 |=UCSSEL_2;   //UART clock is SMCLK
UCA0BR0|=65;         //Baud N=BCLK/rate,rate=9600,BCLK=SMCLK=8M
UCA0BR1|=3;
    UCA0MCTL= UCBRS1;      //UCBRSx=2
UCA0CTL1 &=~UCSWRST;   //UART reset end
}
void UartGpioCfg()
{P1DIR|= BIT6;
P1DIR|= BIT2;         //P1.2UART_TX
P1DIR&=~BIT1;         //P1.1UART_RX
P1SEL|= BIT1+BIT2;      //select P1.1 and P1.2 as UART port
P1SEL2 |= BIT1+BIT2;
}
void UartInit()
{
UartRegCfg();
UartGpioCfg();
}
/************************************************************************
* Function Name : UARTPutChar
* Create Date : 2012/07/27
* Author:
*
* Description :send a character
*
* Param : cTX is willing to send character
************************************************************************/
void UARTPutChar(unsigned char cTX)
{
UCA0TXBUF=cTX;
while (!(IFG2&UCA0TXIFG));//waiting UCA0TXBUF is empty
    IFG2&=~UCA0TXIFG;         //clear TX interrupt flag
}
/************************************************************************
* Function Name : UARTGetChar
* Create Date : 2012/07/27
* Author:
*
* Description :get a character
*
* Param : cRX is willing to get character
************************************************************************/
int UARTGetChar(void)
{
int GetChar=0;
while (!(IFG2&UCA0RXIFG));//UCA1RXBUF has received a complete character
IFG2&=~UCA0RXIFG;         //clear RX interrupt flag
UCA0TXBUF=UCA0RXBUF;      //back to display
GetChar=UCA0RXBUF;
while (!(IFG2&UCA0TXIFG));//waiting UCA0TXBUF is empty
IFG2&=~UCA0TXIFG;         //clear TX interrupt flag
return GetChar;
}
/************************************************************************
* Function Name : UARTPutstring
* Create Date : 2012/07/27
* Author:
*
* Description :output string
*
* Param : char *str point send string
* return: the length of string
************************************************************************/
int UARTPutstring( char *str)
{
   unsigned int uCount=0;
   do
   {
    uCount++;
    UARTPutChar(*str);
   }
   while(*++str!='\0');
   UARTPutChar('\n');
   return uCount;
}
void SysCtlClockInit()
{
    DCOCTL=0;
    BCSCTL1=CALBC1_16MHZ;
    DCOCTL =CALDCO_16MHZ;
    BCSCTL1|=DIVA_1;    //ACLK =MCLK/2=8M
    BCSCTL2|=DIVS_1;    //SMCLK=MCLK/2=8M
}

void main()
{
WDTCTL = WDTPW + WDTHOLD;
SysCtlClockInit();
UartInit();
UARTGetChar();
while(1);
}

LIZHAOBO_1988 发表于 2012-9-14 16:31:03

你 UARTPutChar中的cTX 是unsigned char 类型的,而UARTGetChar中的getchar是int型的,会不会是这个原因。

LY1208798815 发表于 2012-9-25 10:16:16

{:smile:}{:smile:}{:smile:}
页: [1]
查看完整版本: 请求大侠帮忙,为什么这个程序下进去串口调试工具接不到