Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add timeout handling for I2C in Wire#497

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
HanzHager wants to merge14 commits intoarduino:main
base:main
Choose a base branch
Loading
fromHanzHager:main

Conversation

@HanzHager
Copy link

Adding timeout handling for I2C in Wire according to previously defined solution on other platforms
Also reduced the default timeout from 1000ms till 25ms
Also created src directory as well as adding keywords.txt and library.properties so that the "Wire" part of the repository can be handled as a separate library

@CLAassistant
Copy link

CLAassistant commentedOct 8, 2025
edited
Loading

CLA assistant check
All committers have signed the CLA.

@HanzHager
Copy link
Author

This should solve the issue#492

@HanzHager
Copy link
Author

The actions to reset the hardware in handleTimeout() is not well tested. It would be great if someone who knows better can take a look at it to see if it makes sense and if there should be changes.

@per1234per1234 added type: enhancementProposed improvement topic: codeRelated to content of the project itself labelsOct 8, 2025
The new logic for the timeout loop in read_from() and write_to() had a bug. It is now fixed.
Adding timeout handling for I2C in Wire according to previously defined solution on other platformsAlso reduced the default timeout from 1000ms to 25ms
@HanzHager
Copy link
Author

Fixed a bug in timeout handling in read_from() and write_to() and made the commit cleaner

@HanzHager
Copy link
Author

After some more testing I conclude that I need even more testing to make sure it works as intended.
I think that in the current solution, the master may not be able to correctly handle when a device on the bus is stuck in clock stretching. This should most likely be fixed before ever releasing this pull request.

@per1234
Copy link
Collaborator

Thanks for your pull request, and for taking the time to provide an update on the situation@HanzHager!

I see that one of Arduino's developers also submitted a similar pull request:#494

It would be great if you would review that prior pull request and help us to understand whether your PR provides any advancements when compared to the other, and whether the other might also suffer from any of the potential problems you have identified in testing of this PR.

@HanzHager
Copy link
Author

Thanks for your pull request, and for taking the time to provide an update on the situation@HanzHager!

I see that one of Arduino's developers also submitted a similar pull request:#494

It would be great if you would review that prior pull request and help us to understand whether your PR provides any advancements when compared to the other, and whether the other might also suffer from any of the potential problems you have identified in testing of this PR.

I looked at this PR and it looks like it is using setTimeout() instead of setWireTimeout() for the implementation.
There is already a defined way to handle setting timeout for "Wire" and this includes a function called setWireTimeout() as well as other functions described inhttps://docs.arduino.cc/language-reference/en/functions/communication/wire/setWireTimeout/

I have tried to make a complete implementation that harmonizes best with this and the AVR implementation.
Unfortunately, I am not fully confident that I am handling the Renesas api properly and I have realized that there needs to be some considerations for timeout situations where some device on the bus is keeping the SCL line low as result of clock stretching or some fault. So, I guess I need more testing and potentially some help in reviewing and making additional testing my solution, before it is deployed.

I am quite new in making contributions like this, so I probably need quite some guidance to get it right.

per1234 reacted with heart emoji

@HanzHager
Copy link
Author

I just noticed that#494 have renamed the setTimeout() to setWireTimeout(). The function sets timeout in milliseconds, but the referred implementationhttps://docs.arduino.cc/language-reference/en/functions/communication/wire/setWireTimeout/ are using microseconds as well as a boolean second parameter that tells the implementation to reset the bus on timeout or not.
So, even if#494 is small and simple solution, it is not compatible with other implementations and the reference documentation.

This version has more testing and some refinements for handling of timeoutIt still has some printouts and comments that might be useful for others review and testingWhen reviewed and tested, I will remove thisI have also packaged the same files as an independent library that is easy to download and install as a libraryThis can be found at:https://github.com/HanzHager/Wire
@HanzHager
Copy link
Author

I have now updated with a new better tested version, but more testing and review would be great
I order to make testing easier, I have prepared a standalone library that can be downloaded and easily used in the Arduino IDE. It can be found athttps://github.com/HanzHager/Wire (same identical files Wire.cpp and Wire.h)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

topic: codeRelated to content of the project itselftype: enhancementProposed improvement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

I2C scan takes extremely long (~126 seconds) with Wire.endTransmission() on empty bus

3 participants

@HanzHager@CLAassistant@per1234

[8]ページ先頭

©2009-2025 Movatter.jp