msp430launchpad开发板配置UART使用外部晶振32768,波特率为9600,并且利用串口调试工具收发数据,接收出现乱码。将波特率改为4800或者其他,更加无法接收到数据,请哪位高手指点下。
程序:
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_1; // 选择ACLK,对应默认时钟源为LFXT1
///LFXT1= 32768 波特率为9600
UCA0BR0 = 0x03; // 32768 9600
UCA0BR1 = 0; // 32768 9600
UCA0MCTL = 0x4A; // Modulation UCBRSx = 1
///LFXT1= 32768 波特率为9600
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
P1DIR = 0x41; //LED 配置为输出
P1OUT = 0x09; //LED1输出高电平,选择为上拉方式
P1REN = 0x08; //使能上拉电阻
for(;;)
{
__bis_SR_register(LPM3_bits + GIE);
}
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
P1OUT ^= 0x41;
}
调试如下:出现乱码
file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/465524381/QQ/WinTemp/RichOle/FK2E(2Z%25SQ__%7DQJYP11HH67.jpg |