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

#include  "msp430g2553.h"

void main(void)

{

 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

 P1DIR = 0xFF;                             // All P1.x outputs

 P1OUT = 0;                                // All P1.x reset

 P2DIR = 0xFF;                             // All P2.x outputs

 P2OUT = 0;                                // All P2.x reset

 P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

 P1SEL2= BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

 P3DIR = 0xFF;                             // All P3.x outputs

 P3OUT = 0;                                // All P3.x reset  

 UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK

 UCA0BR0 = 0x03;                           // 32kHz/9600 = 3.41

 UCA0BR1 = 0x00;                           //

 UCA0MCTL = UCBRS1 + UCBRS0;               // Modulation UCBRSx = 3

 UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

 IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

 __bis_SR_register(GIE);                   // Enter LPM3, interrupts enabled

}

// 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

}

串口接收中断进不去,串口调试助手看不到数据

  • 你的串口线是如何与电脑连接的?

  • 用示波器看看串口线上有没有波形

  • 可以参考code example,查看哪里有问题

    //******************************************************************************

    //   MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK

    //

    //   Description: Echo a received character, RX ISR used. Normal mode is LPM0.

    //   USCI_A0 RX interrupt triggers TX Echo.

    //   Baud rate divider with 1MHz = 1MHz/9600 = ~104.2

    //   ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz

    //

    //                MSP430G2xx3

    //             -----------------

    //         /|\|              XIN|-

    //          | |                 |

    //          --|RST          XOUT|-

    //            |                 |

    //            |     P1.2/UCA0TXD|------------>

    //            |                 | 9600 - 8N1

    //            |     P1.1/UCA0RXD|<------------

    //

    //   D. Dang

    //   Texas Instruments Inc.

    //   February 2011

    //   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10

    //******************************************************************************

    #include  "msp430g2553.h"

    void main(void)

    {

     WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

     BCSCTL1 = CALBC1_1MHZ;                    // Set DCO

     DCOCTL = CALDCO_1MHZ;

     P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

     P1SEL2 = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

     UCA0CTL1 |= UCSSEL_2;                     // SMCLK

     UCA0BR0 = 104;                            // 1MHz 9600

     UCA0BR1 = 0;                              // 1MHz 9600

     UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1

     UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

     IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

     __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled

    }

    //  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

    }

  • 程序没有太大问题,但是需要单步调试看中断标志位是否在正常接收到上位机发送数据后置位,而且这种配置串口的误码率很高

    建议先尝试1200波特率,或者使用SMCLK尝试9600后在调整时钟源或者波特率

  • 你好!

    有两点要注意:

    1. 新版的eeworld的 launch pad + G2553 连接串口 需要 将 跳线帽 按照HW UART方式跳接;

    2, 使用某些版本的串口调试助手会有问题无法连接,请使用 windows自带的 超级终端 : 开始 --- 附件 --- 通讯工具 --- 超级终端

  • DCO 1MHZ  UCA0BR0=104;  波特率9600 但串口助手接收为乱码,找不到原因。像以前的现象是波特率不对。这个设置应该对啊。