结合很多人的经验,总算把串口发送一个u,然后返回一个helloworld这个程序弄懂了。
话不多说,贴程序。
//******************************************************************************
// 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;
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
for(;;)
{
__bis_SR_register(LPM0_bits + GIE);
}
}
#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++];
}
}
这个程序是本人调试完成成功的。保证绝对正确。如果不正确,肯定是你外部的毛病了。
写的规范的都敝帚自珍,只能我这种三脚猫出来给大家演示了。
WDTCTL = WDTPW + WDTHOLD;这个是什么意思,没有注释看不懂