So you have a Due or Zero. May we get the information which one you're using? The bug you mention is fixed for a while (given I refer to the same problem).
I have a Arduino.org M0 but given the replies in my previous topic, and the generic nature of my problem I thought best not to mention it...
The wiring is simple:
Arduino SDA/SCL to MCP 23017 SDA/SCL using 4K7 pull-up resistors
MCP Reset to 3.3V using 10K resistor
MCP address hardwired to 0x20 using jumpers
GPA0 - GPA4: 5 button LED outputs (each button has an LED inside)
GPB0 - GPB4: 5 button inputs
GPB5: Rotary encoder button input
GPB6/GPB7: Rotary encoder inputs
Freezing the chip is probably not the right term. One possibility I see is that you clear inadvertently the HAEN flag in the configuration register which might change the I2C address until the chip is reset.
If you reset the Arduino and the chip is not responsive run an I2C address scanner. If the chip responds my above guess might be correct.
This was a very good debugging tip! Thank you so much!
I put an I2C scan in my setup()
On first boot 1 device is found with address 0x20
But when the problem occurs and I reset the Arduino,
the scanner detects devices with address
0x01, 0x02, 0x03, 0x04 and then 0x20.
It has to be the chip changing address while scanning because after the scan it becomes responsive again.
But only when using the scanner..
Also the MCP is the only thing we've connected through I2C
Then I accidentally read a thread which I've read before but never connected the dots:
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=91209and then found:
https://microchip.secure.force.com/microchipknowledge/articles/Technical_Support/On-MCP23008-MCP23017-SDA-line-change-when-GPIO7-input-change/?q=mcp23017&l=en_US&fs=Search&pn=1stating pin 7 on either bank is causing problems and can't be used as an input which is very unexpected behaviour for an IC built for the purpose of creating inputs/outputs.
So move the encoder to other pins did solve the problem. We won't be using pin 7 for now as this is unreliable
I have contacted Microchip about this problem, whether it's a design flaw or bad chip, but no reply yet..
Unfortunately I haven't found an alternative to use as I/O expander as most chips are SMD