I2C, getting I2CDR is a problem

Hi,

I’m using the MSP430F167 with the IAR compiler and development tool. My problem is the following: the msp receives a word through the I2C from a pressure sensor. While debugging, when I single step, everything works fine. However, if I let the program run, it seems that the I2CDRW register is not updated with the value from the I2C when I copy it to another register. I’ve found that the transfer works if I add a delay between the I2C communication and the copy of the I2CDRW to another register. In every case the I2C communication works well, the signals are correct.

Any idea?

Thanks

After you set up I2C to read, it takes time before the data actually appears in I2CDR.

There is a bit called RXRDYIFG in the I2CIFG register. This bit is set by the I2C hardware when I2CDR received data. It is cleared when your software reads I2CDR.

Thus you should poll this bit before you try to read I2CDR. Alternatively, you can enable the interrupt and handle the reading in the interrupt service routine so that the CPU can do something else, or go to sleep while waiting for the interrupt.

Thanks for your help, this works!