G2553的I2C
#include "msp430g2553.h"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 = 0x20; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interruptTACCTL0 = CCIE; // TACCR0 interrupt enabled
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
while (1)
{
__bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled
UCB0CTL1 &= ~UCTR; // I2C RX
UCB0CTL1 |= UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX
}
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TA0_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR__interrupt void USCIAB0TX_ISR(void)
{
UCB0TXBUF = (UCB0RXBUF << 4) | 0x0f; // Move RX data to TX
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
这是TI给的I2C例程,为什么打开的是接收中断使能,怎么中断函数又是发送中断的函数? RX_VECTOR包含:USCI_Bx中的UCALIFG、UCNACKIFG、UCSTTIFG 、UCSTPIFG 和USCI_Ax中的UCAxRXIFG
TX_VECTOR包含:UCBxTXIFG、UCBxRXIFG和USCI_Ax中的UCAxTXIFG 我看了一下午才明白 mark……
顶一个… 大森时钟是怎么选的啊?
页:
[1]