In controller mode, the clock
stretching can be disabled if no targets on the bus support it, allowing the
controller to reach the maximum speed on the bus. Otherwise the clock can be slowed
by a target keeping the clock low or due to the clock status detection delay within
the I2C module.
To ensure compliance to the
I2C specification, clock stretching needs to be enabled. Clock
stretching is activated when either the RX FIFO full or TX FIFO empty is set. Clock
stretching support can be enabled or disabled by configuring the CLKSTRETCH bit in
I2Cx.MCR register.
In the target mode, clock stretching
is enabled by default and it is signaled by the TREQ and RREQ bits of the
I2C target status register I2Cx.SSR.
- When TREQ bit is set, it
indicates the I2C controller has been addressed as a target
transmitter and is using clock stretching to delay the controller until data
has been written to the STXDATA FIFO (Target TX FIFO is empty).
- When RREQ bit is set, it
indicates the I2C controller has outstanding receive data from
the I2C controller and is using clock stretching to delay the controller
until the data has been read from the SRXDATA FIFO (Target RX FIFO is
full).
Note: Clock stretching in target mode may be used together with an
asynchronous
fast clock request to support bringing the device into a suspended
low power mode state upon detection of an I2C start bit, enabling the I2C module
to support 100kHz (standard mode) or 400kHz (fast mode) operation out of low
power modes where the bus clock speed is below the minimum oversampling speed
required by the respective mode. Refer to the
clock
selection and I2C speed section for the minimum frequency
requirements. When clock stretching is used together with an asynchronous fast
clock request, it is possible for the device to wait in STOP or STANDBY mode
when the I
2C is idle, and when an I
2C bus edge is seen,
the fast clock request will requests SYSOSC at base frequency and the bus clock
will switch to SYSOSC at base frequency, allowing the I
2C module to
process the bus transaction and wake the processor if an interrupt is
generated.