Chip_I2C_MasterRead not reading multiple bytes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Chip_I2C_MasterRead not reading multiple bytes

1,794 Views
mallikarjunared
Contributor III

Hi,

          I am using i2c on LPC1768 controller, in which i can write the data but i cannot read more then one byte.

Whatever  length i pass  to this function Chip_I2C_MasterRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t *buff, int len)  it will return only one byte.

   What could be my problem ?  can someone help me ?


Regards

Mallikarjun

Labels (1)
0 Kudos
13 Replies

1,376 Views
mallikarjunared
Contributor III

Hi Kerry,

   Thanks for sharing code.

 I want to send ACK in case of 0x58. I am not seeing any 58 case in Interrupt handler in code shared by you. Please help on this.

Thanks,

Mallikarjun

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna Reddy,

   Sorry to send you the wrong project, that is the slave code, you need the master code, not the slave. 0X58 is the master state:

About the state0x58, please do the operation like this which has been described in the user manual:

Data has been received, NOT ACK has been returned. Data will be read from I2DAT. A
STOP condition will be transmitted.
1. Read data byte from I2DAT into Master Receive buffer.
2. Write 0x14 to I2CONSET to set the STO and AA bits.
3. Write 0x08 to I2CONCLR to clear the SI flag.
4. Exit

I have attached the I2C project. 0X50 state is used for data has been received, ACK has been returned. Please refer to the code bundle code to  set the AA bit in the 0x50.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,375 Views
mallikarjunared
Contributor III

Hey Kerry,

        Thanks for reply,

        I have tried setting AA to CONSET register, but i am not seeing any ACK in my Logic Analyzer.

    

With Regards,

Mallikarjuna

0 Kudos

1,375 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna,

Give you a slave LPCxpresso codebundle project for your reference :

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,376 Views
mallikarjunared
Contributor III

Hi Kerry,

    Thanks for support.

    The issue was resolved. 

    I have another question for you.

           How can I Send ACK to Slave from master.

Thanks & Regards,

Mallikarjun

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjun,

  LPC_I2C0->CONSET = I2CONSET_AA;

 This code is used to assert ACK.

 

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,376 Views
mallikarjunared
Contributor III

Hi Kerry,

            

          I m using official code from lpc only. The problem is with I2C Interrupt handler, which doesn't read if the state if NACK(0x58). Which i have fixed.

        Now it is working fine....! Thanks for your support,

        

          

 

Thanks & Regards,

Mallikarjuna

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna,

     Thank you for telling us you make it work.

     When 0x58 happens, it should read the slave data, this is the code from code bundle:

    case 0x58:
    I2CSlaveBuffer[2][RdIndex2++] = LPC_I2C2->DAT;
    I2CMasterState[2] = I2C_OK;
    LPC_I2C2->CONSET = I2CONSET_STO;    /* Set Stop flag */
    LPC_I2C2->CONCLR = I2CONCLR_SIC;    /* Clear SI flag */
    break;

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,376 Views
mallikarjunared
Contributor III

Hey Kerry,

          Thanks for the update.

          The actual problem was with I2C Interrupt handler, which doesn't read if the state if NACK(0x58). 

          

 

Thanks & Regards,

Mallikarjuna

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna Reddy,

   Did you test the official code on your side?

  If you still can't make it work,  you can send me your problem project which just contains the I2C module, and can reflect the problem. I would like to help you to check it.

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,376 Views
mallikarjunared
Contributor III

Hey Kerry,

          Thanks for you kind support.

         The data which i read(1 byte) is correct and the full data is available on i2c bus(i have tested with logic analyzer).

           Looks like issue is with i2C Master( i.e LPC  controller).

Thanks & Regards,

Mallikarjuna

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna Reddy,

    Please try to use the LPCopen I2C code on your side.

    I have test it, and use the Chip_I2C_MasterRead function, it works ok.

  This is the lpcopen test wave:

pastedImage_1.png

You can find it can receive more than one byte.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,376 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mallikarjuna Reddy,

     Whether the master can read the correct data or not, it is not only determined by the master, it is also related to the slave.

     Please check the I2C communication wave between your master and the slave, then post your wave when you can't receive more than one byte.

     Please also refer to the lpcopen code, to check your configuration is correct, you can refer to the LPC1769 I2C code from this link:

LPCOpen Software for LPC17XX|NXP 

Wish it helps you!

If you are still have problem, please contact me!

Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos