#include <msp430f6638.h>
unsigned int MST_Data,SLV_Data;
unsigned char temp;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P8SEL = BIT1+BIT2+BIT3; //USCI_A1的8.2为SIMO,8.3为SOMI,8.1为USCI_A1的CLK
P8DIR = BIT3; //SOMI端口设为输出
P8DIR &= ~BIT2; // SIMO端口设为输入
P8DIR &= ~BIT1; //CLK设为输入
P1REN |= BIT4; // Enable P1.4 internal resistance
P1OUT |= BIT4; // Set P1.4 as pull-Up resistance
P1IES &= ~BIT4; // P1.4 Lo/Hi edge
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IE |= BIT4; // P1.4 interrupt enabled
UCA1CTL1|=UCSWRST;
UCA1CTL0|= UCSYNC+UCCKPL+UCMSB;
UCA1CTL1&=~UCSWRST;
__bis_SR_register(LPM0_bits+GIE);
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0: break;
case 2:
while (!(UCA1IFG&UCTXIFG))
UCA1TXBUF = UCA1RXBUF;
__delay_cycles(500);
break;
case 4: break;
default: break;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT4; // Clear P1.4 IFG
P1IE &= ~ BIT4; // Clear P1.4 IE
UCA1CTL1 |= UCSWRST; // Master is ready
UCA1CTL1 &= ~UCSWRST; // Re-init slave state machine
UCA1IE |= UCRXIE; // Enable RX interrupt |