I2C slave clock stretching to allow time to prepare response data
I have the following setup: Master<---------I2C------------>STM slave
The master communicates like this:
1) Master I2C write: [Start bit, I2C address (from master)], [Req Data1 (from master)]
2) Master I2C read: [Start bit, I2C address (from master)], [Resp Data1 (from slave)],......,[Resp DataN (from slave)]
With a "vanilla" STM slave implementation there is a problem because the STM slave requires time in between (1) and (2) to decode the "request type" byte and prepare the response data. However the master has no delay between (1) and (2), so the result is that the initial response bytes are invalid.
Normally this sort of issue is handled on slave I2C devices by clock stretching. In the STM32F401RE user manual the description of the clock stretching implementation seems to suggest that it operates on a single I2C transfer, not between I2C transfers. Is that correct? For example from the diagram below is it possible to hold clock stretching beyond EV4?
I've had trouble finding STM I2C slave example code (I guess normally it is the master) and the examples that I have found don't have custom clock stretching.
Can someone explain to me how to implement clock stretching between I2C transfers? Or perhaps there is a better way to prevent the master clocking the slave data out before it is ready?