Skip to content

Prevent I2C lockups #32

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
wants to merge 4 commits into from
Closed

Prevent I2C lockups #32

wants to merge 4 commits into from

Conversation

paynterf
Copy link

back in 2010 Nirea (see http://forum.arduino.cc/index.php/topic,19624.0.html) posted an effective method for preventing I2C lockups, but somehow his mods (or any of several different attempts at this) never made it into the baseline code. This pull request proposes his changes, plus the addition of a 'lockup_reset_counter' and associated 'get' and 'clear' functions.

The changes involve very straightforward modifications to Wire.cpp/h and twi.c/h. I have tested these mods on an Arduino Mega 2560 with 2 slave devices (an Adafruit RTC and a DFRobots IMU6050 module); before the mods, the best I could do was a few hours without a lockup, but after the mods my test project ran for over three days (60+ hours) before I stopped the test.

TIA,

Frank

   void clearRecoveryCount();
   uint16_t getRecoveryCount();
   void clearRecoveryCount();
   uint16_t getRecoveryCount();
…o prevent lockup when the I2C bus fails to respond as expected. In addition, a lockup_recovery_count variable was added, along with lockup_counter 'get' and 'clear' functions
@matthijskooijman
Copy link
Collaborator

Thanks for your contribution! Having some fix for the lockups would be great, however, one problem with timeouts is that some applications might have significant clock stretching, would could be broken by a change like this.

As for the PR itself, your commits contains ton of whitespace changes, which makes the PR hard to review and impossible to merge. Commit messages do not need to contain the date, git tracks this. I'm not sure what gfp means? Finally, function declarations are best added in the same commit as the related function definitions, since these are part of a single logical change.

@paynterf
Copy link
Author

paynterf commented Aug 16, 2018 via email

@matthijskooijman
Copy link
Collaborator

I've no idea what you mean about the white space - I just added the code changes and committed/pushed to my repo. Do you mean extra lines, or maybe whitespace added due to changes between tabs and spaces (I think Win10 likes to change things between tabs and spaces). In any case, do you have a recommendation for addressing this issue?

If you look at the diff of the commit (here by clicking "commits" or "Files changed") or in whatever program you're using to commit, which is always a good idea before creating a PR), you'll see that a lot of lines are changed, but most of them only change whitespace or indentation. These changes are meaningless and mess up history, so we'd rather not have them. As for removing them - that might not be so easy, unfortunately. You might be able to do some search-replacing to undo the changes (and use rebase / history rewriting to actually fix the existing commits), otherwise it might be easier to start from scratch and make sure your editor only changes what you're typing, and does not try to "fix" everything or force a particular indentation style (best practice is to preserve the existing style).

Sorry about the dates - how do I fix that?

You'll have to use some history-rewriting in git, such as the rebase command. That can be a bit complicated, so I can't give you the 101 here. Google should have plenty info, though. IIRC https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History is a good resource (also the rest of that book).

'gfp' is my initials; I grew used to doing this in the old days (there was software before Git) so other collaborators know who the culprit was

I suspected as much: no need, git will remember you made the change. This also applies for adding comments in files stating the date and the change made. There are such comments in existing files, but they are no longer used.

Not sure what you mean by ' function declarations are best added in the same commit as the related function definitions, since these are part of a single logical change.' Was it because I used separate commits for each file?

Yup, it is better to use a single commit for each logical change, which makes them more self-contained and easy to review (now, and in years to come). That changes are in different files is completely irrelevant - git can also tell us that already :-)

@matthijskooijman
Copy link
Collaborator

One more thing: If you manage to get things fixed up with history-rewriting, you can do a force push to your github branch, and this PR will be automatically updated, replacing the old commits with your new changes.

@paynterf
Copy link
Author

paynterf commented Aug 17, 2018 via email

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@paynterf
Copy link
Author

paynterf commented Apr 9, 2021 via email

@matthijskooijman
Copy link
Collaborator

Hm, it seems this one was left open, but a similar change has since been merged with #107, so I'll go ahead and close this PR.

The CLA assistent comment was just an automated comment that was posted to all open PRs, so can be ignored here :-)

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.

3 participants