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

not handling I2C slave clock stretching #319

Closed
incanus opened this issue Oct 5, 2022 · 3 comments
Closed

not handling I2C slave clock stretching #319

incanus opened this issue Oct 5, 2022 · 3 comments

Comments

@incanus
Copy link

incanus commented Oct 5, 2022

I have a peripheral (that I'm also in control of) connected to a Pi Zero 2 over I2C; only sending bytes from the Pi. I have clock stretching enabled in the peripheral so that when I get to a fairly rapid rate of transfer, the peripheral can hold the clock line low until it's ready for more.

However, in the i2cmaster.cpp code, the ERR flag is checked on the S (status) register first, which then returns from CI2CMaster::Write() as if a NACK had occurred. Only after that code is the CLKT flag checked.

The problem is that in my testing, both flags are set during a clock stretch, so an error is triggered first and the clock stretch result is never triggered. I can rearrange the if loop conditions and reliably get a clock stretch return value (where I have also confirmed the error flag set).

I'm curious if there's any historical reasoning here? I do see cd22971 with reference to class CI2CMaster works now similar to bcm2835 I2C library.

@rsta2
Copy link
Owner

rsta2 commented Oct 6, 2022

The I2C master driver in Circle has been ported from Mike McCauley's bcm2835 library. The previous implementation was done on my own and had multiple issues.

According to this hardware errata page I2C clock stretching is not reliable on write and does work on read only on specific conditions in the Raspberry Pi's SoC. I cannot say, if clock stretching could be used at all for your specific purpose with the RPi Zero 2.

If it would help to rearrange the checks of the status conditions (ERR, CLKT) after the transfer, this could be changed in the Circle driver. Please let me know, if this would help you.

@incanus
Copy link
Author

incanus commented Oct 6, 2022

Thanks, I was more inquiring for info to start. Now that I look at bmc2835, I do see the similarity. Thank you also for the errata link. For now, I will continue testing, but I will come back here to either request that change or close this issue out soon.

@incanus
Copy link
Author

incanus commented Oct 13, 2022

After more testing, based on some of the unrelated intricacies of my setup, this doesn't make a practical difference. So things are fine in the project as is. Thanks again.

@incanus incanus closed this as completed Oct 13, 2022
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