Skip to content

More I2C / Wire issues #289

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

Closed
paulvha opened this issue Oct 18, 2020 · 1 comment
Closed

More I2C / Wire issues #289

paulvha opened this issue Oct 18, 2020 · 1 comment
Milestone

Comments

@paulvha
Copy link
Contributor

paulvha commented Oct 18, 2020

Trying to get my SPS30 going on Apollo3 2.0.1, I run into the following issues:
I2C speed.
From Wire.begin() master the mbed::I2C() is called, part of mbed-os/drivers/source/I2C.cpp. In I2C::I2C(PinName sda, PinName scl) it is stated that " // The init function also set the frequency to 100000". This is incorrect as function I2C_init(), in TARGET_ambiq_micro/TARGET_Apollo3/Device/i2c_api.c, will use the DEFAULT_CLK_FREQ. This is defined in line 30 in the same file as AM_HAL_IOM_400KHZ and thus different than assumed. This should be corrected for both Master-calls as well as I2C slave-calls else the different driver files are out of sync and the user (me) confused why the SPS30 did not work. I just called frequency(_hz) at the end of I2C::I2C, but it's better to set the DEFAULT_CLK_FREQ to AM_HAL_IOM_100KHZ.

RX buffer clear
In Wire.requestFrom() an rxBuffer.clear() should be performed BEFORE adding new content with rxBuffer.store_char. Now old content from a previous requestFrom call, which has not been read completely by user-level, is returned as if it is the result of the new requestFrom(). Any Wire.cpp on other boards perform this clear first as well. I have tested and added rxBuffer.clear() and that worked as expected.

Intialize
The variables master and slave should initialized as NULL when the Wire constructor is created. Now it is assumed they a NULL and checked in begin().

I2C examples
The current I2C example is corect BUT very complicated and there should be a better explanation of how to use the IOM modules to add a new I2C channel. (see https://forum.sparkfun.com/viewtopic.php?f=169&t=53961)

regards,
Paul

@Wenn0101 Wenn0101 added this to the v2.1.0 milestone Mar 2, 2021
@Wenn0101
Copy link
Contributor

I2C Speed is changed, master and slave are initialized to NULL.

I have done my best simplifying the example a bit, but I may still add a better one in the future.

The RX buffer clear, I ended up not doing this change. I felt as if the data from a previous requestFrom should still be available, even if another has been called. Since each requestFrom returns a length, the amount of data each request has returned should be available.

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

No branches or pull requests

2 participants