cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

jawa_294416
New Contributor II

 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

0 Likes
7 Replies
Anonymous
Not applicable
        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= READ(); // read function here   
}   
You said want to read more 256 bytes   
Where to read?   
volts is 3*3=9 bytes   
0 Likes
jawa_294416
New Contributor II

 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]

0 Likes
JoMe_264151
Expert II

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

0 Likes
JoMe_264151
Expert II

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.

0 Likes
jawa_294416
New Contributor II

 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.

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

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.

0 Likes