This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI的硬件发送与接收中断

Other Parts Discussed in Thread: MSP430G2553

//******************************************************************************

//   MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK

//

//   Description: Echo a received character, RX ISR used. Normal mode is LPM0.

//   USCI_A0 RX interrupt triggers TX Echo.

//   Baud rate divider with 1MHz = 1MHz/9600 = ~104.2

//   ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz

//

//                MSP430G2xx3

//             -----------------

//         /|\|              XIN|-

//          | |                 |

//          --|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"

#include  "SPI.h"

#define uchar unsigned char

#define uint  unsigned int

unsigned char seg[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

volatile uint x=0;

uchar DataBuffer[]="MSP430 is ready";

unsigned char MST_Data, SLV_Data;

void main(void)

{

 WDTCTL = WDTPW + WDTHOLD;

 // Stop WDT

 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

 P1DIR |= BIT2;                             // All P1.x outputs

 P1DIR &=~BIT1;

 UCA0CTL1 |= UCSWRST;

 UCA0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC;  // 3-pin, 8-bit SPI master

 UCA0CTL1 |= UCSSEL_2;                     // SMCLK

 UCA0BR0 = 0x02;                            // 1MHz 9600

 UCA0BR1 = 0;                              // 1MHz 9600

 UCA0MCTL = 0;                        // Modulation UCBRSx = 1

 UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

 //IE2 |= UCA0RXIE+UCA0TXIE;                          // Enable USCI_A0 RX interrupt

 //_EINT();

 __bis_SR_register(GIE);       // Enter LPM0, interrupts enabled

 while(1)                    //串口测试

 {

   SpiWriteData(0X20);     //只写入

   char a = SpiWriteData(0xff);    //只读取

 }

}

/*********************************************************************  

* 函 数 名: void UartRx()

* 功能描述: SPI接收中断函数

* 函数说明: 更新接收中断标志位

* 调用函数:

* 全局变量: 无

* 输    入: 无

* 返    回: 无

***********************************************************************/

#pragma vector=USCIAB0RX_VECTOR

__interrupt void USCIA0RX_ISR()

{

 while(!(IFG2 & UCA0TXIFG));

 UCA0RxFlag=1;                          //置为接收中断标志位

 //__low_power_mode_off_on_exit();        //退出接收中断的低功耗模式

}

/*********************************************************************  

* 函 数 名: void UartTx ()

* 功能描述: SPI发送中断函数

* 函数说明: 更新SPI发送中断标志位

* 调用函数:

* 全局变量: 无

* 输    入: 无

* 返    回: 无

***********************************************************************/

#pragma vector=USCIAB0TX_VECTOR

__interrupt void USCIA0TX_ISR ()

{

 while(!(IFG2 & UCA0TXIFG));

 UCA0TxFlag=1;                         //置为发送中断标志位

 //__low_power_mode_off_on_exit();       //退出低功耗模式

}

为什么进入到中断里面以后就出不来了