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.

CCS/MSP430I2041: UCB0BCNT not incremented after first byte transmitted over I2C

Part Number: MSP430I2041

Tool/software: Code Composer Studio

Hi all,

I am trying to use UCB0BCNT as an index when sending multi-byte I2C responses from a slave. The problem is that UCB0BCNT seems to only increment after the second byte being sent.

The user guide says: "The byte counter is incremented at the second bit position of each byte independently of the following ACK or NACK. A START or RESTART condition resets the counter value to zero. Address bytes do not increment the counter. The byte counter is also incremented at the second byte position, if an arbitration lost occurs during the first bit of data."

I take this to mean that if I send a byte, the byte counter should increment as the second bit is sent, meaning that when I send my next byte the counter should have been incremented.

Here's my MSP430 code:

void i2c_initialize(uint8_t address) {
    /**
     * Configure I2C pins for I2C.
     */
    P1SEL0 |=   BIT6 | BIT7;
    P1SEL1 &= ~(BIT6 | BIT7);

    /**
     * Configure USCI_B0 for I2C slave mode.
     */
    UCB0CTLW0 |= UCSWRST;            // Software reset enabled
    UCB0CTLW0 |= UCMODE_3 | UCSYNC;  // I2C slave mode
    UCB0I2COA0 = address | UCOAEN;   // Address + enable
    UCB0CTL1 &= ~UCSWRST;            // Software reset disabled
    UCB0IE |= UCTXIE0;               // Enable interrupts
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt void USCIB0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
#else
#error Compiler not supported!
#endif
{
    switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG)) {
        case USCI_NONE: break;
        case USCI_I2C_UCALIFG: break;
        case USCI_I2C_UCNACKIFG: break;
        case USCI_I2C_UCSTTIFG: break;
        case USCI_I2C_UCSTPIFG: break;
        case USCI_I2C_UCRXIFG3: break;
        case USCI_I2C_UCTXIFG3: break;
        case USCI_I2C_UCRXIFG2: break;
        case USCI_I2C_UCTXIFG2: break;
        case USCI_I2C_UCRXIFG1: break;
        case USCI_I2C_UCTXIFG1: break;
        case USCI_I2C_UCRXIFG0: break;
        case USCI_I2C_UCTXIFG0:
            UCB0TXBUF = UCB0BCNT;
            break;
        case USCI_I2C_UCBCNTIFG: break;
        case USCI_I2C_UCCLTOIFG: break;
        case USCI_I2C_UCBIT9IFG: break;
        default: break;
    }
}

And from my master, if I perform 3 reads of 5 bytes each, I get:

MSP430 read 0, 0, 1, 2, 3.
MSP430 read 0, 0, 1, 2, 3.
MSP430 read 0, 0, 1, 2, 3.

Can anyone explain why the byte counter doesn't increment after the first byte?

Thanks,

Jason

**Attention** This is a public forum