Regarding PSoC4 I2C reset for I2C slave hang up(SDA is low)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
YuMa_1534086
Level 7
Level 7
Distributor - Macnica (Japan)
500 replies posted 250 sign-ins 10 likes received

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

1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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.

PSoC 5LP I2C Bus Reset Sample

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

View solution in original post

0 Likes
2 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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.

PSoC 5LP I2C Bus Reset Sample

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

0 Likes
YuMa_1534086
Level 7
Level 7
Distributor - Macnica (Japan)
500 replies posted 250 sign-ins 10 likes received

Dear Tanaka-san.

Thank you for your response.

I would like to refer to your answer and sample code!

Best Regards.

Yutaka Matsubara