IAR 5.4
#include "msp430g2553.h"
typedef unsigned char uint8;
typedef unsigned int uint16 ;
volatile unsigned char RxByte;
void CLK_Init();
void UART_Init(void);
void UART_Tx1Byte(unsigned char Txdata);
void UART_TxString(unsigned char *pTxString);
unsigned char su[]="hello world!!!";
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
CLK_Init();
UART_Init();
UART_TxString(su);
_NOP();
__bis_SR_register(LPM3 + GIE); // Enter LPM3 w/ interrupts enabled
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
P1DIR |= BIT6;
P1OUT |= BIT6;
RxByte = UCA0RXBUF; // Display RX'ed charater
}
void CLK_Init()
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // 挂起
}
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; //设置DCO模式
BCSCTL3 |= LFXT1S_0;
while(IFG1 & OFIFG)
{
IFG1 &= ~OFIFG; //清除OSCFault 标志
__delay_cycles(100000); //为可见标志延时
}
}
void UART_Init(void)
{
/*外部功能选择*/
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2;
/*选择时钟*/
UCA0CTL1 |= UCSSEL_1; // CLK = SMCLK
/*选择波特率*/
UCA0BR0 = 0x03; // 32kHz/9600 = 3.41
UCA0BR1 = 0x00;
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3
/**/
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE ; // Enable USCI_A0 RX interrupt
}
void UART_Tx1Byte(unsigned char TxByte)
{
while(UCA0STAT & UCBUSY);
UCA0TXBUF = TxByte;
}
void UART_TxString(unsigned char *pTxString)
{
while(*pTxString)
{
UART_Tx1Byte(*pTxString++);
}
}
通过串口调试助手发送毫无压力但是不能接收 ,调试发现死活 进入不了接收中断啊 ,
而且试了一下官方的例子(已改为HW) , 也不能进入啊
怎么回事啊
该怎么做 , 详细一点
Hardy Hu:
1.程序里面配置的USCI-A模块即UART的时钟是SMCLK,但是主程序最后一句进入了LPM3模式,这个模式SMCLK是关闭的,所以没办法触发接受中断
2.需要把USCI-A模块的时钟配置成ACLK或者让MCU只进入LPM0。