|
我将单片机与蓝牙连接,与手机进行通信(蓝牙串口助手),单片机可以发送数据给手机,但手机发送不了数据给单片机,调试时,发现进不去UART接收中断,这是什么原因?急求指教!!!
#include "msp430G2553.h"
#include "in430.h"
void UartPutchar(unsigned char c);
unsigned char UartGetchar();
unsigned char temp=0;
unsigned char number[2]={0};
void main( void )
{
unsigned int i=0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1DIR|=BIT6;
P1OUT&=~BIT6;
P1SEL = BIT1 + BIT2; // P1.1为 RXD, P1.2为TXD
P1SEL2 = BIT1 + BIT2; // P1.1为 RXD, P1.2为TXD
UCA0CTL1 |= UCSSEL_2; // 选择时钟BRCLK
UCA0BR0 = 106; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS2 + UCBRS0; // 波特率=BRCLK/(UBR+(M7+...0)/8)
UCA0CTL1 &= ~UCSWRST;
// 初始化顺序:SWRST=1设置串口,然后设置SWRST=0,最后设置相应中断
//IE2 |= UCA0RXIE; // 使能接收中断
_EINT();
while(i<5)
{
UartPutchar(9);
// display_int(temp,0);
__delay_cycles(10000);
i++;
}
while(1);
}
//UART接收中断
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
temp=UartGetchar();
}
//UART发送字节函数
void UartPutchar(unsigned char c)
{
while(!(IFG2 & UCA0TXIFG)); //待发送为空
UCA0TXBUF=c;
IFG2 &=~UCA0RXIFG;
}
//UART接收字节数据
unsigned char UartGetchar()
{
unsigned char c;
while(!(IFG2 & UCA0RXIFG)); //等待接收完成
c=UCA0RXBUF;
IFG2 &=~UCA0TXIFG;
return c;
}
|
|