MSP430F149的两个USATR 在实现SPI通讯,采用中断接受
#include <msp430x14x.h>
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
P1OUT = 0x00; // P1.0 setup for LED output
P1DIR |= 0x03;
P5SEL |= 0x0E; // P5.1,2,3 SPI option select
P5OUT &= ~0x01;
P5DIR |= 0x01; //Reset Slave
P5DIR &= ~0x01;
U1CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U1TCTL = CKPL + SSEL1 + STC; // Polarity, SMCLK, 3-wire
U1BR0 = 0x02; // SPICLK = SMCLK/2
U1BR1 = 0x00;
U1MCTL = 0x00;
ME2 |= USPIE1; // Module enable
U1CTL &= ~SWRST; // SPI enable
IE2 |= URXIE1 + UTXIE1; // RX and TX interrupt enable
for (i = 0xFFF; i > 0; i--); // Time for slave to ready
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=USART1RX_VECTOR
__interrupt void SPI1_rx (void)
{
P1OUT = RXBUF1; // RXBUF1 to TXBUF1
}
#pragma vector=USART1TX_VECTOR
__interrupt void SPI1_tx (void)
{
unsigned int i;
i = P1IN;
i = i >> 4;
TXBUF1 = i; // Transmit character
}
|