cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

New Contributor II

Hello,

In order to read 6 bytes from an I2C slave device I used the following code:

rc = I2CM_MasterWriteBuf(0x5A, pDataWrite, 1, I2CM_MODE_NO_STOP);

1 .while(I2CM_MasterStatus() & I2CM_MSTAT_XFER_INP);

rc = I2CM_MasterReadBuf(0x5A, pDataRead, 6, I2CM_MODE_REPEAT_START);

2. while(I2CM_MasterStatus() & I2CM_MSTAT_XFER_INP);

I managed to read the data from the slave deivce only if the bold lines are replaced with:

CyDelay(1u);

Can you please explain how can I avoid CyDelay and check transfer completion ?

Thank you in advance,

Zvika

0 Likes
Reply
1 Solution
Contributor II

You may be falling right through your while() statements if the transfer hasn't actually begun yet when you check them.  the WriteBuf/ReadBuf functions prepare the buffers and begin the operation, but interrupts take care actually moving the data in and out one byte at a time.  Someone would have to confirm this, but I suspect the busy flag may not set until a a short time after ReadBuf/WriteBuf are called.

You could try using the transfer completed flags rather than the busy flags:

I2CM_MSTAT_WR_CMPLT and I2CM_MSTAT_RD_CMPLT respectively.

View solution in original post

3 Replies
Contributor II

You may be falling right through your while() statements if the transfer hasn't actually begun yet when you check them.  the WriteBuf/ReadBuf functions prepare the buffers and begin the operation, but interrupts take care actually moving the data in and out one byte at a time.  Someone would have to confirm this, but I suspect the busy flag may not set until a a short time after ReadBuf/WriteBuf are called.

You could try using the transfer completed flags rather than the busy flags:

I2CM_MSTAT_WR_CMPLT and I2CM_MSTAT_RD_CMPLT respectively.

View solution in original post

New Contributor II

Hello,

Thank you very much !

Best regards,

Zvika

0 Likes
Reply
New Contributor II

I had a similar issue in implementing a slave driver on a PSOC3. I ended up using an ISR callback. In the PSOC3. If you are running master mode there may be a similar call as well. Just look in the ISR module.

In my case, I was polling based on a Cypress example that I was using and ended up dropping messages. Using the interrupts fixed the problem. To use the callback you have to define it in cyapicalls.h.

void I2C_1_I2C_SlaveCompleteCallback(void)

{

    uint32_t i2c_status = I2C_1_I2CSlaveStatus();

    // Only interested in write complete and read complete

    // Write complete indicates that the master has finished writing the slave

    // Read complete inicates that the master has finished reading the slave

    if (I2C_1_I2C_SSTAT_WR_CMPLT & i2c_status)

    {

        pd_control_i2c_master_write_complete();

    }

    if (I2C_1_I2C_SSTAT_RD_CMPLT & i2c_status)

    {

        pd_control_i2c_master_read_complete();

    }

}

0 Likes
Reply