I've connected a rotary encoder through an MCP23017 I/O Port expander to an Arduino and have some trouble with it. Bank B is used as input (buttons and encoder) bank A is used as output (LEDs in Bank B buttons) Pull-up resistors are applied to:
- all input pins (10K)
- SDA and SCL pins (4K7)
- Reset pin (10K).
When I rotate the rotary encoder, after some time the board freezes and becomes unresponsive. Resetting the Arduino alone leaves the IC in it's current state, initiates setup() but never finishes. Resetting the IC and Arduino; the IC resets and setup() completes, therefore concluding the problem lies in the IC. The time till it freezes seems completely random. Everything works as espected untill freezing. No while loops, delays or other blocking programming is used.
So far I've tried:
- Reading using loop() polling
- Reading using interrupts (setting flag in ISR and reading value in loop())
- Reading free ram for memory overflow
- Debouncing reading of variables
- Setting I2C frequency specifically to 400kHz
- Removing all Serial/SerialUSB calls
- Using standalone power adapter (5V 2A)
- Removing reset Pull-up makes no difference
- Removing SDA/SCL Pull-up makes no difference
- Using Wire or Adafruit-MCP23017 library makes no difference.
- My Arduino is ARM based so the "Wire while loop fix" does not apply here.
What could be causing the IC to freeze entirely?
Is there something I can try to debug this problem?