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

read8 error handling #101

Open
Carl-UB opened this issue May 1, 2024 · 0 comments
Open

read8 error handling #101

Carl-UB opened this issue May 1, 2024 · 0 comments

Comments

@Carl-UB
Copy link

Carl-UB commented May 1, 2024

Board: ESP32 (AZ-Delivery Devkit v4)
IDE: VSCode/PlatformIO

The read8 function does not check for errors when calling write_then_read:

uint8_t Adafruit_PWMServoDriver::read8(uint8_t addr) {
uint8_t buffer[1] = {addr};
i2c_dev->write_then_read(buffer, 1, buffer, 1);
return buffer[0];
}

If write_then_read returns false, then read8 may return an incorrect value. In my case it was just returning 0xFE (PCA9685_PRESCALE) as that was the address that was failing to read. This is problematic since 0xFE is a valid return value (and similarly for other addresses, they may also be valid return values) so errors cannot be distinguished.

It would be better if it could at least detect this error and indicate an error in some manner. read8 is private so could be changed without changing the interface.

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

No branches or pull requests

1 participant