Below my code:
int Read_TMP102(unsigned char TMPaddr)
{
// Protocol Base >>[START BIT][ADDR+R/W][REGISTER][DATA1][DATA2][STOP BIT]
//I2C description document TI SLAU144J - page 461 (www.ti.com/.../slau144j.pdf)
while((UCB0STAT & BUSY)!= 0); // free bus
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition to sent
// this part of code send the command to set the register that will be read.
// command format = [start_bit][address + r/w][command to read][stop bit]
i2c_tx(TMPaddr); // this function transmit the I2C address 0x48 ( TMP102) + register.
i2c_stop(); // generate de stop bit.
while((UCB0STAT & BUSY)!= 0); // verify if bus is free
//start the read command
UCB0CTL1 &= ~UCTR; // change I2C controller to receive mode, in this point address is loaded ( UCBxI2CCSA = slave address)
UCB0CTL1 |= UCTXSTT;
while((IFG2 & UCB0RXIFG )==0); // send start condiction to transceiver
RX_INH = UCB0RXBUF;
while((IFG2 & UCB0RXIFG )==0); // wait to receive a new byte.
RX_INL = UCB0RXBUF;
//GENERATE STOP BIT
//while((UCB0STAT & BUSY)!= 0); // generate the stop condiction
UCB0CTL1 |= UCTXSTP;
while(UCB0CTL1 & UCTXSTP);
Data_out = (int)RX_INH<<8;
Data_out +=(int)RX_INL;
__delay_cycles(10);
return Data_out;
}
The strange behavior is that in first time that I sent the read command the MSP send one extra clock train and with it I receive that ACK of last TMP byte, after The MSP send only the correct number or train clock.
the TMP102 is configured with 0x60A0 ( default). All ack perfect.
After it i send command to set and read the sensor
Sensor response the commands but now in I2C appear a new clock byte. FF ( that is wrong), but the data measured but sensor is right . After it I send a new command to read the temperature again but now dont have the last byte.
I receive the last byte but now the NAK happen, and again the information is right. I verified the registes before and after the both trasmission and is everything same .
Someone can help me solve this problem. Thanks