a353183177 发表于 2012-7-29 10:45:09

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例程,为什么打开的是接收中断使能,怎么中断函数又是发送中断的函数?

ly3too 发表于 2013-4-28 17:13:44

RX_VECTOR包含:USCI_Bx中的UCALIFG、UCNACKIFG、UCSTTIFG 、UCSTPIFG      和USCI_Ax中的UCAxRXIFG
TX_VECTOR包含:UCBxTXIFG、UCBxRXIFG和USCI_Ax中的UCAxTXIFG

ly3too 发表于 2013-4-28 17:14:00

我看了一下午才明白

xiefy21 发表于 2013-8-12 11:13:58

mark……
顶一个…

CandD 发表于 2014-6-21 20:26:02

大森时钟是怎么选的啊?
页: [1]
查看完整版本: G2553的I2C