Reset I2C

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

cross mob
Anonymous
Not applicable

Hello,

   

if i load a new firmware to my pSoC4 sometimes a connected I2C-Slave hang (SDA is low).

   

I have to disconnect the power to reset the slave.

   

Can i reset the I2C Bus from the master?

   

 

   

Günter

0 Likes
1 Solution
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Hello All,

   

 

   

High-Speed I/O Matrix  (HSIOM)  multiplexes pin and connects to a particular peripheral selected in HSIOM_PORT_SELx register. Please make use of below code to control SCL pin using firmware.

   
regVal = CY_GET_REG32(I2C_scl__0__HSIOM);
regVal &= ~I2C_scl__0__HSIOM_MASK;
   
/* Set Pin as GPIO controlled by firmware */
regVal = CY_SET_REG32(I2C_scl__0__HSIOM, regVal |(I2C_scl__0__HSIOM_GPIO <<I2C_scl__0__HSIOM_SHIFT)); 
   
/* Set Pin drive mode */    
I2C_scl_SetDriveMode(I2C_scl_DM_STRONG);      
   
/* Toggle Pin with 100-ms delay */
   
 I2C_scl_Write(0u);
 CyDelay(100u);
 I2C_scl_Write(1u);
 CyDelay(100u);
   
 
   

Thanks and Regards,
 Geona Mary

View solution in original post

0 Likes
17 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I made the same experience with some I2C devices. Now I disconnect them before I re-program my PSoC or -as you did- power down the system. No chance to reset the slave except it has got a command or a reset line.

   

 

   

Bob

   

PS: Where in Europe are you located?

0 Likes
Anonymous
Not applicable

Hello Bob,

   

i think the slave waits for additional clock to complete a byte.

   

In other microcontrollers i toggle Scl and wait until SDA is high. Then i send a stop condition.

   

But i am new to the pSoCs...

   

P.S. Germany

   

 

   

Günter

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Unfortunately there is no timeout defined in the I2C protocol, so you may give youe solution a try.

   

 

   

Bob

   

PS: Yes, I thought Germany or Austria. I live near Bremen, and you are from...?

0 Likes
Anonymous
Not applicable

Hello Bob,

   

i live near Ulm.

   

When i force the SCL to ground with a jumper for a short moment, SDA goes high!

   

How can i manipulate the Pin SCL when it is attached to the I2C SCB?

   

 

   

Günter

0 Likes
Anonymous
Not applicable

CY_SYS_PINS_CLEAR_PIN (CYREG_PRT3_DR, 0);
CyDelay(1);
CY_SYS_PINS_SET_PIN (CYREG_PRT3_DR, 0);

   

 

   

dont work...

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

The Cypress I2C has a stall condition and is being looked at as

   

fix in future releases. Has to do with start condition and buss

   

setup.

   

 

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may give this a try

   

 

   

I2C_Reset(void)// Set scl lowwhile(I2C_sda_Read() == 0) Wait(); // Wait until sda is high// Release scl lineBob

   

void

   

{

   

I2C_scl_Write(0);

   

 

   

 

   

 

   

I2C_scl_Write(1);

   

 

   

}

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Forum software clobbered my text. attaching a text-file

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello Bob,

   

 

   

I2C_1_sda_Read() works fine, but I2C_1_scl_Write(0); dont work. I can measure no Pulse on SCL.

   

 

   

Now i can detect the problem with I2C_1_sda_Read() and hold the pSoc in a loop. A short pulse to ground with a jumper and the I2C bus works fine.

   

So the only problem is to get the SCL-PIN down a few times...

   

 

   

Günter

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Digging deeper into the sources...

   

Please check this one...

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thans Bob,

   

 

   

it works!

   

 

   


    while(I2C_1_sda_Read() == 0) // SDA hang low
    {
        I2C_1_SET_I2C_SCL_HSIOM_SEL(I2C_1_HSIOM_GPIO_SEL); //Switch to GPIO   
        I2C_1_scl_Write(0);
        CyDelay(1);
        I2C_1_scl_Write(1);
        CyDelay(1);
        I2C_1_SET_I2C_SCL_HSIOM_SEL(I2C_1_HSIOM_I2C_SEL); //Switch to Component
    }
    I2C_1_I2CMasterSendStop();
 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Great! Did you try what happens when there is no I2C device is connected? Would be bad if program hangs.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello Bob,

   

without a slave SDA will be high, so everyting is OK.

   

 

   

Thanks for your help!

0 Likes
Anonymous
Not applicable

Hello Cypress,

   

 

   

it would be nice to have such a function builtin  in the I2C component. It is better try to a I2Creset after a timeout than die in a endless loop...

   

 

   

Günter

Anonymous
Not applicable

Hi Bob and Günter -

   

Unfortunately, I am having the same problem, and the I2C_SET_I2C_SCL_HSIOM_SEL command does not appear to be supported in SCB IP components later than V0. I tried commenting out that line and simply went straight to I2C_scl_Write(0), but it would not assert my I2C clock line low. I was wondering if you had any alternatives using newer versions of the SCB component? FYI, I also tried I2C_I2CReStartGeneration() with no effect on the clock line.

   

Thank you,
Kevin

0 Likes
Anonymous
Not applicable

Hi Kevin,

   

Did you get any solution for writing to the scl pin?

   

Bob,

   

I am facing the same problem as Kevin

   

--

   

I2CM_SET_I2C_SCL_HSIOM_SEL command does not appear to be supported in SCB IP components later than V0. I tried commenting out that line and simply went straight to I2C_scl_Write(0), but it would not assert my I2C clock line low. I was wondering if you had any alternatives using newer versions of the SCB component? 

   

 

   

Regards,

   

Vivek

0 Likes
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Hello All,

   

 

   

High-Speed I/O Matrix  (HSIOM)  multiplexes pin and connects to a particular peripheral selected in HSIOM_PORT_SELx register. Please make use of below code to control SCL pin using firmware.

   
regVal = CY_GET_REG32(I2C_scl__0__HSIOM);
regVal &= ~I2C_scl__0__HSIOM_MASK;
   
/* Set Pin as GPIO controlled by firmware */
regVal = CY_SET_REG32(I2C_scl__0__HSIOM, regVal |(I2C_scl__0__HSIOM_GPIO <<I2C_scl__0__HSIOM_SHIFT)); 
   
/* Set Pin drive mode */    
I2C_scl_SetDriveMode(I2C_scl_DM_STRONG);      
   
/* Toggle Pin with 100-ms delay */
   
 I2C_scl_Write(0u);
 CyDelay(100u);
 I2C_scl_Write(1u);
 CyDelay(100u);
   
 
   

Thanks and Regards,
 Geona Mary

0 Likes