- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Cypress.
I2C slave hang up(SDA is low) occurs sometimes when PSoC4(I2C master) reads I2C slave device.
I added the following code(Reset I2C) at between I2CM_Start and each clear code to solve I2C hang up.
The following code seems reset I2C correctly.
But I don't know if this code is the best description for resetting I2C.
Could you please let us know if there are points that need to be corrected or added?
And is I2CM_I2CMasterSendStop(timeout) unnecessary?
It looks like it was reset correctly even if I2CMasterSendStop is deleted.
=========================================================
I2CM_Start();
//Reset I2C
while(I2CM_sda_Read() == 0){
uint32 regVal, regValtemp;
regVal = CY_GET_REG32(I2CM_scl__0__HSIOM);
regValtemp = regVal;
regValtemp &= ~I2CM_scl__0__HSIOM_MASK;
regValtemp = CY_SET_REG32(I2CM_scl__0__HSIOM, regValtemp |(I2CM_scl__0__HSIOM_GPIO <<I2CM_scl__0__HSIOM_SHIFT));
I2CM_scl_SetDriveMode(I2CM_scl_DM_STRONG);
I2CM_scl_Write(0u);
CyDelay(100u);
I2CM_scl_Write(1u);
CyDelay(100u);
regVal = CY_SET_REG32(I2CM_scl__0__HSIOM, regVal);
}
status = I2CM_I2CMasterSendStop(timeout);
//Reset I2C
I2CM_I2CMasterClearStatus();
I2CM_I2CMasterClearReadBuf();
I2CM_I2CMasterClearWriteBuf();
=========================================================
Best Regards.
Yutaka Matsubara
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Matsubara-san,
This is a very nice post!
I posted a similar topic for 5LP, but I could not figure out how to do this with PSoC 4.
BTW, one thing I noticed is (well, I must admit that I'm picky),
in case the slave device does not recover by flipping SCL,
this Reset I2C function could hang there, too.
So I would have some reasonable maximum number to repeat and give up after that.
Usually I read that about 1 byte amount is enough, but in my experience there were
sensors which requires 2 bytes transfer for each transaction, so I set the number to 16
in my 5LP sample.
Best Regards,
16-Oct-2019
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Matsubara-san,
This is a very nice post!
I posted a similar topic for 5LP, but I could not figure out how to do this with PSoC 4.
BTW, one thing I noticed is (well, I must admit that I'm picky),
in case the slave device does not recover by flipping SCL,
this Reset I2C function could hang there, too.
So I would have some reasonable maximum number to repeat and give up after that.
Usually I read that about 1 byte amount is enough, but in my experience there were
sensors which requires 2 bytes transfer for each transaction, so I set the number to 16
in my 5LP sample.
Best Regards,
16-Oct-2019
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Tanaka-san.
Thank you for your response.
I would like to refer to your answer and sample code!
Best Regards.
Yutaka Matsubara