Hello,
I am trying to solve a problem to get values from my Freescale MMA8453Q Accelerometer with my MSP430g2553 via USCI I2C, where i need to send a repeated start condition.
The slau144j states: "Setting UCTXSTT will generate a repeated START condition. In this case, UCTR may be set or cleared to configure transmitter or receiver, and a different slave address may be written into UCBxI2CSA if desired."
I am using the TI_USCI_I2C_master library, which i wanted to adapt to send repeated start on a certain occasion. The Library is used in the following way:
_EINT(); TI_USCI_I2C_transmitinit(0x1C,I2C_CLKSPEED); // init transmitting with while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(2,Data1); // start transmitting While ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,Data2); // start transmitting while (TI_USCI_I2C_notready() ); TI_USCI_I2C_receiveinit(0x1C,I2C_CLKSPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(3,Data3); while ( TI_USCI_I2C_notready() ); // wait for bus to be free
I changed the library to not send a stop condition if the RSFlag is 3, which only happens the last time Data is transmitted:
#pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { if (IFG2 & UCB0RXIFG) { //Receive if (RSFlag == 3) { if (byteCtr == 0) { UCB0CTL1 |= UCTXSTP; // I2C stop condition *TI_receive_field = UCB0RXBUF; TI_receive_field++; } else { *TI_receive_field = UCB0RXBUF; TI_receive_field++; byteCtr--; } } else { RSFlag++; // Increase Flag to secure 3rd start is a RS if (byteCtr == 0) { //UCB0CTL1 |= UCTXSTP; // I2C stop condition removed *TI_receive_field = UCB0RXBUF; TI_receive_field++; } else { *TI_receive_field = UCB0RXBUF; TI_receive_field++; byteCtr--; } } } else { // Transmit if (RSFlag == 3) { if (byteCtr == 0) { UCB0CTL1 |= UCTXSTP; // I2C stop condition IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag } else { UCB0TXBUF = *TI_transmit_field; TI_transmit_field++; byteCtr--; } } else { RSFlag++; // Increase RSFlag to make sure 3rd Start is RS if (byteCtr == 0) { //UCB0CTL1 |= UCTXSTP; // I2C stop condition removed IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag } else { UCB0TXBUF = *TI_transmit_field; TI_transmit_field++; byteCtr--; } } } }
However, when debugging, the device gets stuck in TI_USCI_I2C_notready() even at the first transmit already, which i can't explain.
Thanks for the help,
Florian
EDIT: Code formatted and adapted some text for better readability