Other Parts Discussed in Thread: CC430F5137
I can't seem to find an example of this so let's start from the beginning. I'm using a CC430F5137 and trying to communicate with an Invensense Motion Sensor, address 68, and just trying to read "Who am I" at Reg 75 using I2C.
Can I assume the UCTXSTT start will add the R/W bit based on the value of UCTR?
Then if I want to read 75, then should I write 68, then write again with SST (~UCTR) again and pick it up in the ISR under Case 10?
Thanks! John
Init: UCB0I2CSA = 0x68;
Then in Main:
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(LPM0_bits+GIE); // Enter LPM0, enable interrupts
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent (Maybe I shouldn't do this yet)
UCB0CTL1 &= ~UCTR; // I2C RX mode,
UCB0CTL1 |= UCTXSTT; // I2C TX, start condition
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
ISR Code:
Case 10: // RX
UCB0IFG &= ~UCRXIFG;
Data= UCB0RXBUF;
Case 12: //TX
if (I2cTxByteCtr == 1) {
UCB0TXBUF = 0X75; // The register I want to read (probably should be a variable)
I2cTxByteCtr = I2cTxByteCtr - 1; // Decrement TX byte counter
} else {
UCB0CTL1 |= UCTXSTP; // I2C stop condition
UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
I2cTxByteCtr = 1;
}