cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

YoIs_1298666
Contributor II

Hello,

Can the I2C slave component of PSoC4000S stretch SCL?

If it can not stretch SCL, is it possible to make stretch circuit with SmartIO and output pins?

Best regards,

Yocchi

0 Likes
1 Solution
TaeY_56
Employee

Hi Yocchi,

Yes, I2C slave can use 'Clock Stretching', but there is no configuration box in component configuration tab to enable clock stretching implementation. So you should make some customized functions.

In order to use clock stretching in I2C component, you should

1) Assign an interrupt callback function which is executed at I2C address match.

2) Make I2C SCL line to low until data have been loaded into I2C buffer you want to transmit.

3) Make I2C SCL line to high after loading has been done.

There is an example source code (page 48) in Component Data Sheet

You can see the source code, how to assign the callback function and controlling I2C SCL line.

Thank you,

Teddy.

View solution in original post

0 Likes
10 Replies
Hari
Moderator
Moderator

Hello

The EzI2C slave component can stretch the clock. This can be enabled by selecting the checkbox in Configure ->EZI2C Basics -> Clock Stretching.

Thanks and regards

Harigovind

0 Likes
YoIs_1298666
Contributor II

Hello Harigovind-san,

Thank you very much for your response.

But we need I2C slave component, not EZI2C.

Best regards,

Yocchi

0 Likes
TaeY_56
Employee

Hi Yocchi,

Yes, I2C slave can use 'Clock Stretching', but there is no configuration box in component configuration tab to enable clock stretching implementation. So you should make some customized functions.

In order to use clock stretching in I2C component, you should

1) Assign an interrupt callback function which is executed at I2C address match.

2) Make I2C SCL line to low until data have been loaded into I2C buffer you want to transmit.

3) Make I2C SCL line to high after loading has been done.

There is an example source code (page 48) in Component Data Sheet

You can see the source code, how to assign the callback function and controlling I2C SCL line.

Thank you,

Teddy.

View solution in original post

0 Likes
TaeY_56
Employee

I made a mistake that the source code doesn't include how to control I2C SCL line.

You can control the line by 'void SCB_scl_Write(uint8 value)' API stored in SCB.scl.cI2C_scl_write API.PNG

0 Likes
YoIs_1298666
Contributor II

Hello TeddyY_56,

I can only find the below callback funcion.

I2CS_SCB_IRQ_Interrupt_InterruptCallback()

Can I write in it?

Best regards,

Yocchi

0 Likes
TaeY_56
Employee

No, it isn't.

i meant the below callback function.

The function is written in page 49 in the linked document above.

CustomInterruptCallback Function.PNG

0 Likes
YoIs_1298666
Contributor II

Hello TeddyY_56,

Thank you very much for your good advice.

Can I stretch the clock after "slave address" and "R/W bit"?

Best regards,

Yocchi

0 Likes
TaeY_56
Employee

No it is not essential, the source code is used for the only example.

Thank you,

Teddy.

0 Likes
YoIs_1298666
Contributor II

Hello Teddy-san,

Thank you very much for your hints.

The Ack for "Slave Address"+"R/Wbit" is stretched by firmware in the interrupt hunder of I2CS component.

pastedImage_0.png

pastedImage_2.png

So, for example  in the "I2CS_I2C_ISR_EntryCallback();" the ACK will be stretched until i2csStretch_flag become 0.

pastedImage_4.png

/*******************************************************************************

*  I2C clock stretch interrupt handler

*******************************************************************************/

void I2CS_I2C_ISR_EntryCallback(void)

{

    if (I2CS_CHECK_INTR_SLAVE_MASKED(I2CS_INTR_SLAVE_I2C_ADDR_MATCH))

    {

        while(i2csStretch_flag){}

    }

    else

    {

        ......

    }

Best regards,

Yocchi

0 Likes
TaeY_56
Employee

You're welcome, i am just pleased for that my answer has been helpful to you.

Thank you,

Teddy.

0 Likes