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

当main函数中有while(1){...},msp430g2553的硬件串口(USCI_A0)不能进入接收中断函数,一直在执行while中东西,请问在保留while的基础上有办法进入接收中断吗?谢谢

  • 下面的代码已测试,请您试一下。使用的是G2553  Launchpad

    #include "msp430g2553.h"
    
    #define TXLED BIT0
    #define RXLED BIT6
    #define TXD BIT2
    #define RXD BIT1
    
    const char string[] = { "Hello World\r\n" };
    unsigned int i; //Counter
    
    int main(void)
    {
       WDTCTL = WDTPW + WDTHOLD; // Stop WDT
       DCOCTL = 0; // Select lowest DCOx and MODx settings
       BCSCTL1 = CALBC1_1MHZ; // Set DCO
       DCOCTL = CALDCO_1MHZ;
       P2DIR |= 0xFF; // All P2.x outputs
       P2OUT &= 0x00; // All P2.x reset
       P1SEL |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD
       P1SEL2 |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD
       P1DIR |= RXLED + TXLED;
       P1OUT &= 0x00;
       UCA0CTL1 |= UCSSEL_2; // SMCLK
       UCA0BR0 = 104;                            // 1MHz 9600
       UCA0BR1 = 0;                              // 1MHz 9600
       UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
       UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
       UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
       __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed
       while (1)
       { }
    }
    
    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR(void)
    {
       P1OUT |= TXLED;
         UCA0TXBUF = string[i++]; // TX next character
        if (i == sizeof string - 1) // TX over?
           UC0IE &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
        P1OUT &= ~TXLED; }
    
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
       P1OUT |= RXLED;
        if (UCA0RXBUF == 'a') // 'a' received?
        {
           i = 0;
           UC0IE |= UCA0TXIE; // Enable USCI_A0 TX interrupt
          UCA0TXBUF = string[i++];
        }
        P1OUT &= ~RXLED;
    }