AnsweredAssumed Answered

I2C receive problem with KL25Z

Question asked by Roth Kalman on Aug 4, 2013
Latest reply on Aug 4, 2013 by Roth Kalman

Dear Freescale Community!


I've successfully set up a toolchain to program the KL25Z dev board, and I need some kind of help using I2C!


I'am trying to access the onboard inertia sensor, I can address it correctly, I receive ACK on my commands, but when I want to receive data, I cannot get the proper data back.


Example: I want to read out the "Who I am" register, the chip accepts my request, but I cannot get back the 0x2A result, as I should. Here is my code:


I2C0_F |= I2C_F_MULT(0); //erata says MULT with different value of 0 blocks RESTART condition

  I2C0_F |= I2C_F_ICR(63); //~317 kbaud

  I2C0_C1 |= I2C_C1_IICEN_MASK;//enable I2C module

  I2C0_C1 |= I2C_C1_TX_MASK;//set up for transmit

  I2C0_C1 |= I2C_C1_MST_MASK;//I2C START action


  i2c_send_byte(0x3a);//ACK=ok, i tested it

  i2c_send_byte(0x0d);//ACK=ok, i tested it

  I2C0_C1 |= I2C_C1_RSTA_MASK;//restart

  i2c_send_byte(0x3b); //ACK=ok, i tested it

  I2C0_C1 &= ~I2C_C1_TX_MASK; //enable i2c receive

  if(I2C0_D); //trigger receive in I2C bus, Here Iam just reading the data register. If i miss this step I cannot receive anything


  if((I2C0_S & I2C_S_TCF_MASK) != I2C_S_TCF_MASK) break;}

  while(1){ if((I2C0_S & I2C_S_TCF_MASK)) break;}


  I2C0_C1 |= I2C_C1_TXAK_MASK; //generate no ack condition

  I2C0_C1 |= I2C_C1_TX_MASK; //enable transmission, by this the next read of data register will not trigger byte reception

  c=I2C0_D;  //after completion of reception I read out the data register

  if(c == 0x2a) GPIOB_PDOR &=~(1 << 18); //I cannot get the proper result


I hope you can breifly help me, how to receive data on i2c bus!


Thank you in advance!

Roth K.