Hi to all,
(I hope this is the correct forum branch for the topic)
I just found a bug in the MCP23S17 library by Cort Buffington (v.0.2 as currently available), which is linked by this page.
The function pinMode() with one-word parameter contains an unneeded inversion of the value passed, which causes pins specified as inputs to be configured as outputs and vice-versa.
Original:
void MCP::pinMode(unsigned int mode) { // Accept the word…
wordWrite(IODIRA, ~mode); // Call the the generic word writer with start register and the mode cache
_modeCache = ~mode;
}
Correct:
void MCP::pinMode(unsigned int mode) { // Accept the word…
wordWrite(IODIRA, mode); // Call the the generic word writer with start register and the mode cache
_modeCache = mode;
}
This issue causes following behaviour:
- the user configures e.g. all pins as inputs as .pinMode(0xFFFF); .pullupMode(0xFFFF);
- inputs don't seem to work until '1' is written to all pins (.digitalWrite(0xFFFF); )
- at this point, inputs appear to work (!!!), except the polarity inversion (.inputInvert(0xFFFF)) doesn't work.
What really happens is that pins are all configured at outputs; shorting a pin to ground to activate an input does short the output to its max current capacity. Reading the pin returns the actual pin level, which has an apparently legit status, except that keeping meny inputs activated for too long would almost certainly lead to hardware failures.
I already posted a bug report on the github page, but I wanted to warn anyone who used / will use the library to beware.