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

I2C timeout #354

Closed
jerabaul29 opened this issue Feb 18, 2021 · 2 comments
Closed

I2C timeout #354

jerabaul29 opened this issue Feb 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@jerabaul29
Copy link

Is there a way to set an I2C timeout, similar to what is discussed in:

arduino/reference-en#895

?

I looked for it in the documentation, but did not find anything about it :) .

@ghost ghost added the enhancement New feature or request label Mar 2, 2021
@Wenn0101
Copy link
Contributor

Wenn0101 commented Mar 2, 2021

I will have to look into this functionality

@paulvha
Copy link
Contributor

paulvha commented Dec 16, 2021

Recently I completed a deep-dive on I2C on Apollo3 and looked at this. A timeout is already in place, but you can not adjust it. There is no reference call in MBED-OS that allows you to do that.

For Arduino AVR the complete handling of the I2C protocol is done asynchronously in twi.c. The main processor is handling the sending of the start, stop, handle clock stretching, ACK & NAK signals as well as sending each byte by working directly with the different registers of the CPU. It is also checking that all steps are handled correctly. The chance of something going wrong and thus blocking the main processor is indeed a risk for which setting timeout makes sense. Looking at earlier versions on the Arduino AVR (before 1.8.2), there was NO timeout check at all.

In an Apollo3 all I2C communication is handled by Input-Output-Module (IOM4 for Wire). It is working independently of the main processor. It is much more robust as it is focused on one task only and it was built for that. Wire() is using blocking transfer, which means the library is waiting for the IOM to complete the transfer by checking the status register of the IOM. There is already a timeout included of ~0.5s. If sending or receiving is not completed within that time, it will return an error. There is also a non-blocking transfer option, but that is not used by Wire().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants