-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
pinMode1 - Silent failure using 0 vs using OUTPUT. #45
Comments
From Datasheet REV_DQuick test Arduino UNO constantsSerial.println(OUTPUT);
Serial.println(INPUT);
Serial.println(INPUT_PULLUP); results in
So OUTPUT == 1 and INPUT == 0, ==> incorrect documentation. Coderelevant piece of MCP23S17.cpp (about line 134) uint8_t mask = 1 << pin;
// only work with valid
if ((mode == INPUT) || (mode == INPUT_PULLUP))
{
val |= mask; <<<<<<<< sets bit as a 1
}
else if (mode == OUTPUT)
{
val &= ~mask; <<<<<<<<< sets bit to 0
}
// other values won't change val ....
writeReg(dataDirectionRegister, val); ConclusionSo the device behaves as expected when using the constants / defines INPUT and OUTPUT Serious documentation error ==> bug level. Will create a develop branch to start a fix. Note to myself: check examples + MCP23008, MCP23017, MCP23S08 libraries too. |
Which platform do you use? |
Other 3 libraries have the same documentation bug, => create issues. |
Note: bug comes from using the bit mask where 0 means output mode and 1 means input mode. |
Will update the readme.md file to
In the .h file some similar comment. |
@Spaceballs3000 |
In my case the define came from esp32-hal-gpio.h |
@Spaceballs3000 Will merge develop branch(es) later today, (update) did not find problems in the examples. |
Unless you check the return value, I didn't know pinMode1 was failing using 0 vs using OUTPUT. As 0 is invalid.
Noticed OUTPUT is defined as 0x03.
Also the function description is Incorrect i.e. "single pin interface mode: 0 = OUTPUT, 1 = INPUT, 1 = INPUT_PULLUP (==INPUT)"
The text was updated successfully, but these errors were encountered: