Closed sentinelt closed 3 years ago
I think #72 should resolve this.
Instead of adding complex calculation which is likely prone to error, why dont we use some pre configured values, like libopencm3 also does like that http://libopencm3.org/docs/latest/stm32f7/html/i2c__common__v2_8c_source.html#l00456 , that would be easy on cpu also. i find no reason for anyone to use other than standard frequency
Looks like the logic which calculates the value of the TIMINGR register is broken.
The code is located here: https://github.com/stm32-rs/stm32f7xx-hal/blob/master/src/i2c.rs#L338 One obvious problem with it, is that after:
let fscll_mhz: f32 = base_clk_mhz / (scll as f32 + 1.0);
the prescaler is then calculated withlet presc = base_clk_mhz / fscll_mhz;
which could be simplified to justlet presc = sccl + 1;
which is obiously wrong.That said, I could not decipher how the entire logic is even supposed to work...
I see two possible ways to fix the problem:
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/libraries/Wire/src/utility/twi.c#L383