STM32H7 wrong I2C timings ~200kHz

In the code: stm32f0_i2c.c - i2s supposed to work always in 100kHz mode.

There is 50 us per byte, which looks like ~200kHz
This is nice, that it supports it, but for MPU accelerometers that can be crucial.

I’m not sure that I have the right idea of how to fix timing and add proper timing calculations for now.

For now, this is JFY.

It does seem that it currently doesn’t take into account the possible peripheral I2C clock.
The total cycle time is:

((SCLL+1)  + (SCLH+1)) * (PRESC + 1) * T(I2C_CLK)
Or F(I2C_CLK) / (((SCLL+1)  + (SCLH+1)) * (PRESC + 1))

SCLH = 19
SCLL = 15
PRESC = 11

So it’s currently not looking at the I2C peripheral speed at all. Which means all the mcu setups would already need to set the I2C peripheral clock up identically. Which is unlikely.
It’d probably be better to calculate the appropriate PRESC for a given peripheral clock. But I suspect a number of MCUs don’t have accurate logic to identify the peripheral clock speed… so that would be tricky.

1 Like

I think it is fixable.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.