3 Replies Latest reply on Feb 23, 2020 8:51 AM by ZvVe_2582751

    I2C read: Detect transfer completed




      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:



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


      Thank you in advance,


        • 1. Re: I2C read: Detect transfer completed

          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.

          1 of 1 people found this helpful
          • 2. Re: I2C read: Detect transfer completed

            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)






                if (I2C_1_I2C_SSTAT_RD_CMPLT & i2c_status)





            • 3. Re: I2C read: Detect transfer completed



              Thank you very much !


              Best regards,