Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubts on I2C configuration #122

Open
tytouf opened this issue Aug 20, 2020 · 2 comments
Open

Doubts on I2C configuration #122

tytouf opened this issue Aug 20, 2020 · 2 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@tytouf
Copy link

tytouf commented Aug 20, 2020

Hello, I'm trying to use the I2C on a stm32l011 device but the code asserts during the unwrap of presc = u8(presc).unwrap() I believe (it's hard to debug due to the optimizations).
In any case looking at the code, I found the computations of the prescaler value strange : first a ratio is computed as i2cclk / freq - 4 which can be negative in case the apb1 clock is too small and later the prescaler value is computed as ratio / constant_value but I can't find any reference to the constant value (387 for fast-mode and 514 for standard-mode).

The original STM32 library builds on values computed by the STM32CubeMx tool and I can understand why this library does not want to rely on it but are you sure about the code calculating the i2c timing values ?

Looking at the reference manual I found there should be also the possibility of enabling the analog and digital filters. Overall I admit that setting up I2C on this device requires an intensive brain session 😭

@dbrgn dbrgn added help wanted Extra attention is needed question Further information is requested labels Aug 20, 2020
@tytouf
Copy link
Author

tytouf commented Aug 20, 2020

I started looking into how the I2C timings are computed tonight and based on AN4235 from ST and their old excel spreadsheet I wrote this python script to find correct values. The script final output for my configuration returns the same value than STM32CubeMx.
Forcing these values resulted in no assertions but now, i2c code is stuck, waiting for transmission completion.

i2c_timings.py.txt

@tytouf
Copy link
Author

tytouf commented Aug 21, 2020

Cool got it working, I had to change one of my pullups resistors.

The code in the python script is very brute force I don't know if moving it to the i2c initialization function is the right move. Ideally this could be done statically but the APB1 clock (and consequently the i2c kernel clock) is set during runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants