AnsweredAssumed Answered

I2C Concern

Question asked by Jagadeesha Lakshmanaiah on May 12, 2015
Latest reply on May 21, 2015 by Jagadeesha Lakshmanaiah

Hello Guys,

 

I am interfacing MPC5604C with some sensor using I2C.

when I send a slave address data..

I can see the start signal going properly on the line,

but after that both the lines will be low and if I send a slave address I am not seeing anything on the SDA line.

what might be the wrong thing I'm doing?

 

please share if anyone has a code for it.

 

Details:

-> I2C clock 400kbps

-> PB2 - SDA line

    PB3 - SCL line

 

/************* I2C init code ****************************/

  SIU.PSMI[29].R = 0x01;

  /*Function Pad Selected I2C_SCL :- PCR19*/

  SIU.PSMI[30].R = 0x01;

  /*Function Pad Selected I2C_SDA :- PCR18*/

 

  /* Configure I2C PCR register to Select I2C functionality */

  SIU.PCR[18].R = 0x0B20; /* select SDA line */

  SIU.PCR[19].R = 0x0A20; /* select SCL line */

  /*****************************************************************************/

void I2CStart(void)

{

 

  I2C.IBCR.B.MS = 0;

  I2CDelay();

  I2C.IBCR.R |= 0x30;/* Master,Transmit set to 1 */

}

/*****************************************************************************/

Bool I2CWrtByte(uint8_t Byte)

 

  I2C.IBDR.R = (uint8_t)Byte; 

 

  while(!((I2C.IBSR.B.TCF) & (I2C.IBSR.B.IBIF)))

  {

    /* Wait for transfer to complete */

  }

 

  /* Check ACK bit - generate stop seq in case of error */

  if(I2C.IBSR.B.RXAK)

  {

    return FAILURE; /* NoAck */

  }

  else

  {

    return SUCCESS; /* Ack received */

  }

}/* End of I2CWrtByte function */

/*****************************************************************************/

Bool I2CWrite(uint8_t slaveaddrs, uint8_t wordaddrs,uint8_t *data, uint32_t data_len)

{

  Bool Status_u8 = SUCCESS, DataLenCount_u32,Byte_u8;

 

  /* Clear IBSR[IBIF] */

  I2C.IBSR.B.IBIF = 0;

 

  if(!I2C.IBSR.B.IBB)

  {

    /* Send a start condition */

    I2CStart();

   

    /* Send the I2C address of the slave with the R/W bit low */

    Byte_u8 = (uint8_t)((slaveaddrs << 1) & 0xFE);   

    Status_u8 = I2CWrtByte(Byte_u8);

   

    /* check the Ack */

    if(Status_u8 == FAILURE)

    {

      return FAILURE;   

    }

    else

    {

    /* send the word address  */

      Status_u8 = I2CWrtByte(wordaddrs);     

      if(Status_u8 == FAILURE)

      {

        return FAILURE;

      }

      else

      {     

        for(DataLenCount_u32 = 0; DataLenCount_u32 < data_len; DataLenCount_u32++)

        {

          Status_u8 = I2CWrtByte(data[DataLenCount_u32]);   

          if(Status_u8 == FAILURE)

          {

            break;

          }

        }

      }

    }

    if(data_len != 0)

    I2CStop();

  }

  else

  {

      Status_u8 = FAILURE;

  }

 

  /* Clear IBSR[IBIF] */

  I2C.IBSR.B.IBIF = 0;

 

  return Status_u8;

}

Outcomes