How can I use i2c clock stretching in slave mode?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I use i2c clock stretching in slave mode?

1,020 Views
burnyfu
Contributor II

Hi,

   I used the MCU is KEA128 and i creat the i2c slave program through the PE.When i receive the master data I need some time to deal it,so i want to use the clock stretching function.I find the I2C_C2.SBRC = 0 and What can i do to get it to work?

Thank you!
Best regards
0 Kudos
2 Replies

747 Views
egoodii
Senior Contributor III

I would expect the Kinetis slave-mode to automatically assert SCL (stretch the clock) after any ACK/NAK-send UNTIL the I2C data-register is read (like most I2C peripherals in 'slave' mode), so pacing would be automatic.  This does mean that the 'next byte' can be sent from the master WHILE you process the current, but will then just 'sit' in the buffer until you have time to deal with this next one!

0 Kudos

747 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello burny fu,

    I think your problem is not the SBRC problem.

   If your I2C slave can receive the the I2C master data, just don't have enough time to process it.

   These have these ways to solve it:

1. Slow down the master send frequency, don't send very quickly.

  Just give some time to the slave to process the data.

2. simplify your slave code and use the I2C interrupt to receive the data and install to the RAM, then in the main to process it.

  As you know, the PE code is a little complicate and redundancy, in the interrupt, you can write it by yourself, don't use so many functions, just use the register to control it.

Wish these thought can help you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos