This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553定时器与串口兼容性问题,为何一开定时器,串口数据就异常?

Other Parts Discussed in Thread: MSP430G2553

将下面的代码屏蔽后,串口正常输出,

    CCR0 = 500-1; // 500ns
    CCTL0 = CCIE;                             // CCR0 interrupt enabled
    TACTL = TASSEL_2 + MC_1 + TAIE;           // SMCLK, upmode, interrupt

将代码解屏蔽就会输出固定字符如:

9A CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA ...

求解?

代码如下:


#include  "msp430g2553.h"


void UartSendChar(char ch)
{
    while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?
    UCA0TXBUF = ch;
}

static unsigned int s_SysTicks = 0;

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
   
    P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
    P1SEL2 = BIT1 + BIT2;                     

    CCR0 = 500-1; // 500ns
    CCTL0 = CCIE;                             // CCR0 interrupt enabled
    TACTL = TASSEL_2 + MC_1 + TAIE;           // SMCLK, upmode, interrupt

    UCA0CTL1 |= UCSSEL_2;                     // SMCLK
    UCA0BR0 = 104;                            // 1MHz 9600
    UCA0BR1 = 0;                              // 1MHz 9600
    UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

    __enable_interrupt();
   
    unsigned char i = 0;
    unsigned char j = 0;
    for ( ; ;)
    {
        UartSendChar(0xaa);
        UartSendChar(i);
        UartSendChar(0xbb);
        UartSendChar(j);
        i++;
        j += 2;
     }
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
    s_SysTicks++;
}