This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I2C problem on msp430f249

Other Parts Discussed in Thread: MSP430F249

Hello,

I am using msp430f249 controller and I got a problem when interface with TCN75 sensor temperature. here is a segment of code. when I called transmit function, it stuck forever in interrupt vector.

///

void init_I2c()
{
    P3SEL |= 0x06;                            // 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 = 2Mhz, keep SW reset
    UCB0BR0 = 40;                             // fSCL = 2/12 = ~200kHz
    UCB0BR1 = 0;
    UCB0I2CSA = 0x48;                       // Set slave address
    UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
    IE2 |= UCB0RXIE+UCB0TXIE;
}

#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
                             // Decrement RX byte counter
//    if (Rx)
//    {
        if (RxByteCtr)
        {
            Data = UCB0RXBUF;  // Get received byte
            Data = Data<<8;
            RxByteCtr--;
            __bic_SR_register_on_exit(CPUOFF);// Exit LMP0
            UCB0CTL1 |= UCTXSTP;
            sendByte((char)Data);

        }
        else
        {
              Data |= UCB0RXBUF;                    // Get final received byte, // Combine MSB and LSB
              sendByte((char)Data);
              turnLedOn(LED2);
              __delay_cycles(10000000);
              turnLedOff(LED2);
              __delay_cycles(10000000);

        }
//        IFG2 &= ~UCB0RXIFG;
//    }

    /*
    else
    {                                     // Master Transmit
        if (TxByteCtr)
        {
            UCB0TXBUF = 0;                     // Load TX buffer, pointer to temperature register
            TxByteCtr--;
        }
        else
        {
             UCB0CTL1 |= UCTXSTP;                    // I2C stop condition
             __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
        }
        IFG2 &= ~UCB0TXIFG;                     // Clear USCI_B0 TX int flag
    }*/
}

void Transmit(void){
    while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
    UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
    __bis_SR_register(GIE+CPUOFF);        // Enter LPM0 w/ interrupts

}
void Receive(void){
    while (UCB0CTL1 & UCTXSTP);                 // Ensure stop condition got sent
    UCB0CTL1 &= ~UCTR ;                     // Clear UCTR
    UCB0CTL1 |= UCTXSTT;                    // I2C start condition
    while (UCB0CTL1 & UCTXSTT);             // Start condition sent?
    UCB0CTL1 |= UCTXSTP;                    // I2C stop condition
    __bis_SR_register(CPUOFF+GIE);        // Enter LPM0 w/ interrupts
}

////

**Attention** This is a public forum