mattjlewis / diozero

Java Device I/O library that is portable across Single Board Computers and microcontrollers. Tested with Raspberry Pi, Odroid C2, BeagleBone Black, Next Thing CHIP, Asus Tinker Board and Arduinos / Pico. Supports GPIO, I2C, SPI as well as Serial communication. Also known to work with Udoo Quad.
https://www.diozero.com
MIT License
261 stars 59 forks source link

Read MCP23xxx currently set GPIOs directions and pull-up resistor states on initialisation... #126

Closed jozala closed 1 year ago

jozala commented 1 year ago

... instead of setting them to some defaults

This is to avoid changing the state of the pins on application/hardware restart. Changing the states of the pins on the initialisation can cause side effect like blinking lights or opening garage door.

mattjlewis commented 1 year ago

Thank you - have you tested this? Looks ok to me, will take a more detailed look this week.

jozala commented 1 year ago

@mattjlewis Sorry for late reply. I completely forgot about it, because changed code was running flawlessly on 5 devices for the last month. However, since 2 days I was fighting with some I2C communication problems on 2 (out of these 5) devices and after spending many hours tracking the problem I believe this is related to my changes in this PR. I don't know what is going on exactly, because I do not have logic analyzer, but I2C bus gets stuck some time after booting the device (NanoPi Neo in my case). I can see that SDA is stuck in "0" even though it has proper pull up resistor.

I've read MCP23017 datasheet and I do not see why change from this PR could cause this problem, but I do not have much experience in electronics.

Anyway, I am going to work on this code to minimise the "blinking" at the start, but keep it stable first.

@mattjlewis Fell free to revert changes from this PR. I will create another one when I know for sure my changes are rock solid or I understand the problem was caused by something else :) .

I am also open if you'd have any suggestions.