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.

老师,请问下这程序应该怎么调?我试了两个串口调试助手都没反应。。。

Other Parts Discussed in Thread: MSP430G2553

 

//******************************************************************************
// MSP430G2xx3 Demo - USCI_A0, Ultra-Low Pwr UART 9600 String, 32kHz ACLK
//
// Description: This program demonstrates a full-duplex 9600-baud UART using
// USCI_A0 and a 32kHz crystal. The program will wait in LPM3, and will
// respond to a received 'u' character using 8N1 protocol. The response will
// be the string 'Hello World'.
// ACLK = BRCLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO ~1.2MHz
// Baud rate divider with 32768Hz XTAL @9600 = 32768Hz/9600 = 3.41
//* An external watch crystal is required on XIN XOUT for ACLK *//
//
// MSP430G2xx3
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|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"

const char string1[] = { "Hello World\r\n" };
unsigned int i;

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**
IE1 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ int until Byte RXed
}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
UCA0TXBUF = string1[i++]; // TX next character

if (i == sizeof string1 - 1) // TX over?
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if (UCA0RXBUF == 'u') // 'u' received?
{
i = 0;
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
UCA0TXBUF = string1[i++];
}
}

  • Hi zhiwei,

     首先确定你上位机的串口调试助手,波特率和相关的设置都是对的。然后可以在程序的接收中断里面设一个断点,上位机随便发一个数,看程序会不会进入接收中断。如果会进入接收中断的话,可以在上位机上面发送一个字符u,或是你修改接收中断的代码,把字符u改成任何你想要的数字。然后在看看程序会不会进接收中断。如果还会的话,那接收程序基本就没问题。然后在全速执行程序,看上位机能否收到hello world的字符。

    谢谢

    ken

  • 1、让你的MCU不断地向外发信号,任意字符串都可以。

    2、示波器检查是否有波形,波形是否传递到电脑的串口。

    3、使用超级终端接收。

  • 楼主,最后你怎么解决的?我也碰到这个问题了。打断点根本进不去。是我的驱动有问题吗?我没用那个虚拟串口,就用一个usb转ttl的模块实验的,因为我的系统w7 64位不支持这个虚拟串口,然后那两个短接片我也竖过来了。

  • hi andy zhao1,

    建议先测试usb转ttl模块是否正常,可以把模块的tx和rx连接在一起,用串口助手发送字符看能否收到。

    usb转ttl模块没问题,再连接开发板进行调试