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

[adc] Refactor ADS1115 driver #24428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[adc] Refactor ADS1115 driver #24428

wants to merge 1 commit into from

Conversation

niklaut
Copy link
Contributor

@niklaut niklaut commented Feb 28, 2025

Solved Problem

Two main problems:

  1. ADS1115 would not be recognized after a reboot, only after a power cycle.
  2. ADS1115 would spam the console when there were I2C transmission issues due to motor EMI (specifically during takeoff and landing).

The driver code is also a bit too optimistic and doesn't log any comms errors.

Solution

I've refactored the driver to be more robust.

  1. The ADS1115 lacks an ID register, so the driver checked the CONFIG register for default values. This only works once after a power cycle, since the driver reconfigures the CONFIG register and then after a reboot the values don't match any more. I'm now instead checking the threshold registers, since the driver does not touch them.
  2. Debouncing via counter is done to detect if the device failed to prevent spam when a single I2C transaction failed. In addition the channel list is kept as a bitmask to allow retries of failed channels.

Also added perf counter to track comms errors.

Changelog Entry

For release notes:

Bugfix: Robustify ADS1115 driver communications

Alternatives

Burn the I2C garbage.

Test coverage

Tested in hardware by shorting the I2C pins to induce comms failures. Driver recovers and doesn't spam the console.

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.

1 participant