这两天在开发msp430i2021的串口驱动,串口一直发送都是乱码。然后按照ti的例程测试了串口的波特率,发现很不稳定。下面是测试代码
#include "msp430.h"
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL0 |= BIT2 | BIT3; // P1.2/3 eUSCI_A Function
P1SEL1 &= ~(BIT2 | BIT3);
UCA0CTL1 |= UCSWRST; // Hold eUSCI in reset
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 142; // 115200 baud
UCA0BR1 = 0;
UCA0MCTLW = 0x2200; // 16.384MHz/115200 = 142.22 (See UG)
UCA0CTL1 &= ~UCSWRST; // Release from reset
// UCA0IE |= UCRXIE; // Enable RX interrupt
// __bis_SR_register(LPM0_bits | GIE); // Enter LPM0
__no_operation(); // For debugger
while(1)
{
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0xaa; // TX -> RXed character
//__delay_cycles(90000000);
}
}
正常的115200测试的脉冲宽度应该是8.6us,现在测到是6.8~13us,这个差太多了,望大家不吝赐教啊