|
#include "msp430g2553.h"
unsigned int Data[64];
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x48; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE + UCB0TXIE; // Enable TX ready interrupt
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
UCB0TXBUF = 0x80; // Write DAC control byte
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR(void)
{
static int i = 0;
static char FG = 0;
if(FG == 0)
{
Data = UCB0RXBUF;
Data <<= 8;
FG = 1;
}
else
{
Data |= UCB0RXBUF;
i++;
FG = 0;
if(i == 64)
i = 0;
}
}
顺便贴上代码。。。。 |
|