Skip to content

Check for loss of arbitration #284

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Check for loss of arbitration #284

wants to merge 2 commits into from

Conversation

lupalby
Copy link

@lupalby lupalby commented Dec 13, 2017

When initiating an I2C communication as master, there is a chance of losing arbitration of the bus if there are other masters on the bus. This is a perfectly normal scenario and it is handled by trying to start the communication again. If arbitration was lost during the first try, now the bus state is busy so the second call to startTransmissionWIRE will wait until the bus is idle again before retrying.
I made this change on my MKRZERO over a month ago and since then I didn't have any more errors. I have a system with 7 masters on the same I2C bus sending messages at about 10Hz each, so loss of arbitration happens frequently (2 masters starting to communicate at the same time). One of the 2 gets priority over the other while the other loses arbitration. The loser simply retries the communication when loss of arbitration is detected, and everything works smoothly without data loss.
Without this check we can't be aware of any loss of arbitration and the library would detect the NACK without understanding that it was not a real NACK from the slave.

When initiating an I2C communication as master, there is a chance of losing arbitration of the bus if there are other masters on the bus. This is a perfectly normal scenario and it is handled by trying to start the communication again. If arbitration was lost during the first try, now the bus state is busy so the second call to startTransmissionWIRE will wait until the bus is idle again before retrying.
I made this change on my MKRZERO over a month ago and since then I didn't have any more errors. I have a system with 7 masters on the same I2C bus sending messages at about 10Hz each, so loss of arbitration happens frequently (2 masters starting to communicate at the same time). One of the 2 gets priority over the other while the other loses arbitration. The loser simply retries the communication when loss of arbitration is detected, and everything works smoothly without data loss.
Without this check we can't be aware of any loss of arbitration and the library would detect the NACK without understanding that it was not a real NACK from the slave.
@facchinm
Copy link
Member

LGTM, need to test it a bit before merging. @agdl can you take care of it?

@lupalby
Copy link
Author

lupalby commented Dec 13, 2017

@agdl It's me, Alberto :) if you guys need some code to test it I have already something ready

@agdl
Copy link
Member

agdl commented Dec 19, 2017

@lupalby yes please paste the code here. Anyway Did I miss something? Alberto Who? :D

@lupalby
Copy link
Author

lupalby commented Dec 21, 2017

To sum up, unfortunately I found that the code I have cannot be shared easily. In general, you can easily test it having 2 or more Arduino as masters on the same I2C bus trying to perform a read operation with one or more slave devices, possibly as frequently as you can. You will notice that some of the operations will fail if you don't apply the fix I am proposing. The problem is not present when only one master is talking on the bus.

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

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.

4 participants