Go Down

Topic: [SOLVED] MCP23017 with rotary encoder hangs/freezes (Read 2169 times) previous topic - next topic

SnakeMastr805

Nov 23, 2016, 01:41 pm Last Edit: Nov 30, 2016, 04:34 pm by SnakeMastr805
Hello,

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?

pylon

Quote
My Arduino is ARM based so the "Wire while loop fix" does not apply here.
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).

Tell us how you wired the chip. Post your code.

Quote
What could be causing the IC to freeze entirely?
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.

Quote
Is there something I can try to debug this problem?
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.

SnakeMastr805

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=91209
and 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=1

stating 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














SnakeMastr805

#3
Nov 30, 2016, 10:38 am Last Edit: Nov 30, 2016, 10:49 am by SnakeMastr805
I have contacted Microchip about this problem, whether it's a design flaw or bad chip, but no reply yet..
The Microchip response:
Quote
This is a known bug in our MCP23017. We are aware of it and in the process of creating an errata data for this bug.

There is no workaround for this issue except to use a different pin as input.
Microchip acknowledges the issue.
So it's a design bug, all MCP23017 can't use pin GPB/A7 as reliable input.

This thread can be closed or marked as "Solved"

floresta

Quote
This thread can be closed or marked as "Solved"
I believe you do that by editing your original post.

Don

Go Up