Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Conversation

@mpgszhyh
Copy link

I think that the function _readandchangepin will return a 8-bit data, but the variant self.direction is a 16-bit one. Therefore, the original code will lead to losing the direction information of PORT B by masking off the most significant byte of the variant self.direction. Maybe the code should be changed as below.
change the code in Line 95:
self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode)
to
self.direction |= self._readandchangepin(MCP23017_IODIRA, pin, mode)

change the code in Line 95:
self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode)
to 
self.direction |= self._readandchangepin(MCP23017_IODIRA, pin, mode)
@tdicola
Copy link
Contributor

tdicola commented Aug 11, 2014

Thanks for raising the issue. I looked a bit at the code and I think it's doing the right thing right now. When there are 8 or less GPIO pins (like running on an MCP23008 chip) then only 1 byte is needed to represent the direction register. The _readandchangepin function operates on a single byte and returns its new value, so it can be directly assigned to direction in the 8 or less pin case.

For more than 8 pins you're right you have to be careful to not drop the unchanged direction bits, but that's why the code uses boolean OR to preserve the other bits.

I'll close the issue, but let me know if you have an example or issue that can be reproduced with the current code. Thanks!

@tdicola tdicola closed this Aug 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants