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

Support for I2C #26

Merged
merged 5 commits into from
Aug 30, 2021
Merged

Support for I2C #26

merged 5 commits into from
Aug 30, 2021

Conversation

mgottschlag
Copy link
Contributor

This PR adds support for I2C. Most of the code is taken from stm32g0xx-hal, with only minor changes:

  • Clock gating/reset works differently.
  • Pins are specified in a different way.
  • Documentation is improved.

I personally do not like the way the bus is configured - with_timing() imho is not the kind of abstraction that should be in a user-facing API. I guess that there are workflows that require this API, though.

The code is not yet tested - it should be ready for merging once I have performed some basic tests.

Mathias Gottschlag added 2 commits August 27, 2021 10:09
Most of this code is taken from stm32g0xx-hal, with only minor changes to
the way pins are initialized and to the interaction with RCC.
The std::max() meant that scll was always set to 255, resulting in bit
rates that were far too slow. Also, the documentation states that the
clock is divided by PRESC+1, not by 2^(PRESC+1).
@mgottschlag mgottschlag changed the title Draft: Support for I2C Support for I2C Aug 30, 2021
@mgottschlag
Copy link
Contributor Author

After I fixed a bug in the original code (see stm32-rs/stm32g0xx-hal#69), the pull request should now be ready for review/merging. For testing, I executed the i2c-mpu6050 example and verified with an oscilloscope that the bit rate is correct.

@mgottschlag mgottschlag marked this pull request as ready for review August 30, 2021 06:51
@mgottschlag
Copy link
Contributor Author

Oh, and tell me if you want the commits to be squashed, as I usually do.

@luctius
Copy link
Collaborator

luctius commented Aug 30, 2021

This looks good to me, thank you for your effort!

Squashing can be done from by Github.

@luctius luctius merged commit e5d0d6a into stm32-rs:master Aug 30, 2021
@mgottschlag mgottschlag deleted the i2c branch August 30, 2021 07:38
luctius pushed a commit to luctius/stm32g4xx-hal that referenced this pull request Sep 17, 2021
* Add support for I2C.

Most of this code is taken from stm32g0xx-hal, with only minor changes to
the way pins are initialized and to the interaction with RCC.

* Improve the I2C documentation.

* Fix compiler error for devices without I2C4.

* Add an I2C/MPU6050 example (the timing is still broken).

* Fix the I2C bit rate.

The std::max() meant that scll was always set to 255, resulting in bit
rates that were far too slow. Also, the documentation states that the
clock is divided by PRESC+1, not by 2^(PRESC+1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants