I2C Concern

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
3,170件の閲覧回数
jagadeeshalaksh
Contributor II

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;

}

ラベル(1)
タグ(2)
1 解決策
2,607件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

do you have external pull-ups on I2C lines? If not try to set internal weak pull-up at least. Use following PCR setting:

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

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

Attach is a simple example which shows I2C module setting and simple TX code for testing only.

The simple I2C memory driver can be tested too, if I2C memory is connected.

Example was tested with I2C 24LC16B on TRK-MPC5604B.

Regards,

Petr

元の投稿で解決策を見る

4 返答(返信)
2,608件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

do you have external pull-ups on I2C lines? If not try to set internal weak pull-up at least. Use following PCR setting:

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

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

Attach is a simple example which shows I2C module setting and simple TX code for testing only.

The simple I2C memory driver can be tested too, if I2C memory is connected.

Example was tested with I2C 24LC16B on TRK-MPC5604B.

Regards,

Petr

2,606件の閲覧回数
jagadeeshalaksh
Contributor II

Hi Petr Stancik,

Thanks for the settings.

still have some problem..

- when I send a request to read a 2 byte of register data from slave..it reads well when i do step by step execution...

if I give a run in loop for reading 2 bytes of data from same register 1st byte is fine and second byte will 0xFF which is invalid.. further read same register will give 0x00 and Bus will stay BUSY.

what i need to take care to resolve this issue?

Smiles,

Jagadeesha

0 件の賞賛
返信
2,607件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

have you tried to use the I2C_ReadBlock() function from the example I attached?

Or what is your test code for 2 cases you described?

Regards,

Petr

2,607件の閲覧回数
jagadeeshalaksh
Contributor II

Hi Petr Stancik,

it got solved... problem was something different.

some setting were getting override soo..

Smiles,

Jagadeesha

0 件の賞賛
返信