You are here

Problem to read more then 256 bytes form I2C slave | Cypress Semiconductor

Problem to read more then 256 bytes form I2C slave

Summary: 7 Replies, Latest post by SmartPSoC on 16 Dec 2013 05:49 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
vscelwan's picture
User
8 posts

 Hi,

How we can read I2C master more then 256 bytes from slave? Both Master and slave I2C are using PSOC 3.

Slave I2C Sub_Address size(bits) = 16 bits.

    typedef struct _EZI2C_REGS

    {

 

        uint16 stat;    /* R/W variable         */

        uint16 cmd;   /* R/W variable         */

        uint16 volts[3][3]; /* R/W variable         */

        uint16 str[6u];    /* Read only to I2C     */

    } EZI2C_REGS;

EZI2C_REGS  readI2cRegs; 

I2C_UDB_M_MasterReadBuf()  function :automatically reads an entire buffer of data from a slave device. We can't use this function to read single array data or specific location to the stucture.

We try the code on following and it failed to provide correct data.

I2C_UDB_M_MasterClearStatus();

CyDelay(2);

I2C_UDB_M_MasterReadBuf(EZI2C_SLAVE_ADDR, (uint8 *)&readI2cRegs.volts[0], sizeof(readI2cRegs.volts[0]) , I2C_UDB_M_MODE_COMPLETE_XFER);

while(0u == (I2C_UDB_M_MasterStatus() & I2C_UDB_M_MSTAT_RD_CMPLT))

 {

 } 

 

I2C_UDB_M_MasterReadBuf(EZI2C_SLAVE_ADDR, (uint8 *)&readI2cRegs.volts[1], sizeof(readI2cRegs.volts[1]) , I2C_UDB_M_MODE_COMPLETE_XFER);

while(0u == (I2C_UDB_M_MasterStatus() & I2C_UDB_M_MSTAT_RD_CMPLT))

 {

 } 

 

    LCD_PrintInt16(readI2cRegs.volts[0][0]);

    LCD_PrintInt16(readI2cRegs.volts[0][1]);

    LCD_PrintInt16(readI2cRegs.volts[0][2]);

 

It only working by following code. The problem that we need to read more then 256 byte from the slave. How we can do it?

I2C_UDB_M_MasterReadBuf(EZI2C_SLAVE_ADDR, (uint8 *)&readI2cRegs, sizeof(readI2cRegs) , I2C_UDB_M_MODE_COMPLETE_XFER);

 

Thanks

user_119377051's picture
User
866 posts

Look through your code

You had read volts[0] and volts[1], two*3 byte only

Generally to read more bytes, Repeat the read action ...



for(i=0;i<256;i++)

{

... volts[i]= READ(); // read function here

}

You said want to read more 256 bytes

Where to read?

volts is 3*3=9 bytes

vscelwan's picture
User
8 posts

 I have attached the example code. We can't do correct the array shown before we can't proceed to read more then 256 bytes from the slave.

readI2cRegs.volts[1][0]

readI2cRegs.volts[1][1]

readI2cRegs.volts[1][2]

user_1377889's picture
User
10803 posts

Probably the slave is not configured to have more than 256 bytes red. I'm afraid you'll have to show us a bit more of your code since there is no limitation in I2C for the number of bytes to transmit.

If you can show your project(s) openly, we all could have a look at and will find any flaw easily. To do so, in Creator use "File -> Create Workspace Bundle" and attach the resulting files to your next posts (do NOT use Chrome, upload often doesn't work)

 

Bob

user_1377889's picture
User
10803 posts

Ooopsi, I was too hasty! The I2C APIs only accept an uint8 as the count for master and slave.

 

Usual workaround is to read in smaller chunks and the slave has to manage setting up the source address for each chunk after the previous has been read.

 

Bob.

 

 

vscelwan's picture
User
8 posts

 We resolved the problem.

 

Our big mistake that we are using the function I2C_UDB_M_MasterReadBuf(), this function read entire buffer of data from a slave device within 255 bytes. It won't work for data more then 255 bytes.

 

It works well when we are using the function I2C_UDB_M_MasterReadByte(), we tested to read with 316 bytes and we checked all the data is correct.

SmartPSoC's picture
Cypress Employee
79 posts

 Hi,

The EzI2C slave has to configured for 16bit sub address for reading more than 256 bytes.

I2C Master Read API supports reading only 256bytes at time since the count is a uint8 type. So you need to call the MAster Read API multiple times, resetting the EzI2C offset address each time.

 

 

 

SmartPSoC's picture
Cypress Employee
79 posts

I am attaching here an example project to read more that 256 bytes from EZI2C slave using UDB I2C master. Hope it will be useful.

Log in to post new comments.