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.
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
I think I have figured this out, but if someone can confirm my theory that would be very helpful.
I think what is happening is:
1. USCI_I2C_UCTXIFG0 fires, and I load UCB0TXBUF = UCB0BCNT = 0.
2. My byte is loaded into the I2C shift register and the USCI starts sending bits.
3. USCI_I2C_UCTXIFG0 fires again, and I load UCB0TXBUF = UCB0BCNT = 0. It's still 0 because the second bit from the first byte has not yet been sent.
4. The first byte finishes sending so USCI_I2C_UCTXIFG0 fires a third time, and this time UCB0BCNT = 1 because the first byte has sent.
Thanks,
Jason
Hey Jason,
Yes, your logic looks correct to me! The moment your first byte is transferred to the shift register, TXIFG0 fires again to get the next byte pre-loaded. This is leading to you transmitting twice.
I also wanted to point you to a standard I2C Slave software example we have available: http://dev.ti.com/tirex/explore/node?node=AMw9w1udhtIrpm2pjwKOxA__IOGqZri__LATEST
Thanks,
JD
Thanks JD! And I appreciate the link to the I2C slave. I had not yet seen that example. FYI, it looks like there are errors in the description at the top of http://dev.ti.com/tirex/nodeContent?node=AHs0-dizYPTbBIT6mD-bNw__IOGqZri__LATEST.
**Attention** This is a public forum