程序是这样的,但是串口调试助手无法接收到数据我理想的效果是向430发送hello,430回复hello world
#include <msp430g2553.h>
void main(void)
{
WDTCTL=WDTPW+WDTHOLD; // Stop WDT
if(CALBC1_1MHZ==0XFF)
{
while(1);
}
DCOCTL=0;
BCSCTL1=CALBC1_1MHZ;// 设置DCO 为1MHz
DCOCTL=CALDCO_1MHZ;
P1SEL=BIT1+BIT2; //P1.1 = RXD, P1.2=TXD
P1SEL2=BIT1+BIT2;
UCA0CTL1|=UCSSEL_2;
UCA0BR0|=0X6D;
UCA0BR1|=0X00;
UCA0MCTL|=0X81;
UCA0CTL1&=~UCSWRST;//**Initialize USCI state machine** 初始化释放,可以操作
IE2|=UCA0RXIE; // Enable USCI_A0 RX interrupt 接收中断使能
__bis_SR_register(LPM0_bits+GIE);//Enter LPM0, interrupts enabled
}
char A[10]={0};
char *B="hello world!";
static int i=0;
void wxd() //输出函数
{
if((A[0]=='h')&&(A[1]=='e')&&(A[2]=='l')&&(A[3]=='l')&&(A[4]=='0')&&(A[5]=='!'))
{
int j;
for(j=0;j<13;j++)
{
IE2 &= ~UCA0RXIE;
UCA0TXBUF=B[j];
int k=0;
for(k=0;k<10000;k++);
}
IE2 |=UCA0RXIE;
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while(!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready? 等待TX buffer为空
{A[i]=UCA0RXBUF;
i++;
}
wxd();
}
此帖出自
小平头技术问答
一周热门 更多>