Hey man, we are have pretty much the same problem with our K60.
We are using I2C protocol to talk to a DPOL (voltage regulator) on the DPOL there are registers we are trying to read.
Below is our C code that we are using, the problem we are getting is that the i2c_wait() function is hang up our program. I was reading somewhere it has to could do with the master (MCU) not sending ACK bit to slave chip.
Plus let us know if you figure it out or find any information. And we will do the same.
void Read_Iout(void)
{
unsigned char byte1,byte2,byte3,read_I2C0_S;
byte1=0;
byte2=0;
byte3=0;
i2c_Start();
// DPOL Address with Write bit
I2C0_D = 0x38;
read_I2C0_S=I2C0_S;
printf("After DPOL address sent I2C0_S: %3d\n",read_I2C0_S);
i2c_Wait();
printf(" DPOL Address Sent (W)\n");
/* Write Register Address */
I2C0_D = 0x8C;
i2c_Wait();
printf(" Register Address Sent\n");
/* Do a repeated start */
I2C0_C1 |= I2C_C1_RSTA_MASK;
/* Send Slave Address */
I2C0_D = 0x39; //read address
i2c_Wait();
printf(" DPOL Address Sent (R)\n");
/* Put in Rx Mode */
I2C0_C1 &= (~I2C_C1_TX_MASK);
/* Ensure TXAK bit is 0 */
I2C0_C1 &= ~I2C_C1_TXAK_MASK;
/* Dummy read */
byte1 = I2C0_D ;
printf("Dummy Read: %3d\n",byte1);
i2c_Wait();
/* Read first byte */
byte1 = I2C0_D;
i2c_Wait();
/* Turn off ACK since this is second to last read*/
I2C0_C1 |= I2C_C1_TXAK_MASK;
/* Read second byte */
byte2 = I2C0_D;
i2c_Wait();
/* Send stop */
i2c_Stop();
/* Read third byte */
byte3 = I2C0_D;
printf("%3d %3d %3d\n",byte1,byte2,byte3);
}
//Here is the wait function definition:
#define i2c_Wait() while((I2C0_S & I2C_S_IICIF_MASK)==0) {} \
I2C0_S |= I2C_S_IICIF_MASK;
// I2C_S_IICIF_MASK= 0x2u this checks the IICIF field which is defined as follows: