MSPP430F2619串口求助!!!

2019-08-03 17:52发布

调了一整天,串口有数据但是波特率不对,求大神帮帮忙。程序如下:
#define uint  unsigned int
#define uchar unsigned char

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 UartInit()
{
   
    P3SEL |=BIT4+BIT5;         //发送和接收引脚为第2功能
    UCA0CTL1 |=UCSWRST;      //reset UART module,as well as enable UART module
    UCA0CTL1 |=UCSSEL_2;     //UART clock is SMCLK
    UCA0BR0  |=0x41;           //Baud N=BCLK/rate,rate=9600,BCLK=SMCLK=8M
    UCA0BR1  |=0x03;
    UCA0MCTL  = UCBRS_1;      //UCBRSx=2
    UCA0CTL1 &= ~UCSWRST;
    //IE2 |= UCA0RXIE;           //接收中断使能
}
/************************************************************************
* 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
************************************************************************/
uchar UARTGetChar(void)
{
    uchar GetChar;
    while (!(IFG2 & UCA0RXIFG));  //UCA1RXBUF has received a complete character
    IFG2&=~UCA0RXIFG;           //clear RX interrupt flag
    GetChar  =UCA0RXBUF;
    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!='');
   UARTPutChar(' ');
   return uCount;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
15条回答
往事随风丶
2019-08-05 15:39
DCOCTL = DCO0 + DCO1 + DCO2;              // Max DCO
  BCSCTL1 = RSEL0 + RSEL1 + RSEL2;          // XT2on, max RSEL
  BCSCTL2 |= SELS;                          // SMCLK = XT2
  P5DIR |= 0x70;                            // P5.6,5,4 outputs
  P5SEL |= 0x70;                            // P5.6,5,5 options
ACLK;32.7680KHz,MCLK:4.95MHz,SMCLK没有

一周热门 更多>