1 of 1 people found this helpful
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.
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.
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)
Thank you very much !