我利用官方给的程序进行串口通信,想在串口助手上输出一段字符串,可是串口助手没有反应,麻烦大家帮忙看看,谢谢啦。
这是代码:
#include <msp430.h>
#include <math.h>
unsigned char buffer[]={"I'm MSP430!\n"};
void delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}
void main(void)
{
unsigned int i;
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Setup P2.4 UCA0RXD, P2.5 UCA0TXD
P2SEL |= BIT4 | BIT5; // Set P2.4, P2.5 to non-IO
P2DIR |= BIT4 | BIT5; // Enable UCA0RXD, UCA0TXD
//Setup LFXT1
UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1 fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
// Setup eUSCI_A0
UCA0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCSSEL_1; // CLK = ACLK
UCA0BRW_L = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA0BRW_H = 0x00;
UCA0MCTLW = 0x5300; // Modulation UCBRSx=0x53, UCBRFx=0
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCTXIE; // Enable USCI_A0 RX interrupt
while(1)
{
while (!(UCA0IFG & UCTXIFG)) ; // USCI_A0 TX buffer ready?
for(i=0;i<sizeof(buffer);i++)
{
UCA0TXBUF=buffer[i];
delay(20);
}
}
}