bobvann
Posts: 4
Joined: Sat Sep 19, 2015 7:14 pm

MCP23017 Interrupts not Raising

Sat Sep 19, 2015 7:22 pm

Hi everybody,

I am trying to use the interrupts of the mcp23017 with the raspberry Pi.

I am writing my own python interface for the module, so I am just using the RPi.GPIO library for detecting the state of the interrupt pin and smbus python module to communicate with the mcp23017 by i2c.

I easily managed to input and output when asked, but what I would like to do is to have interrupts when the state of any of the pins of the "B side" changes.

So I bridged together INTA and INTB pins and connected to the GPIO 7 of the RPi.

Then I did the following

>>> G.bus.write_byte_data(G.DEVICE, G.IODIR_B, 0xff)
>>> G.bus.write_byte_data(G.DEVICE, G.DEFVAL_B, 0)
>>> G.bus.write_byte_data(G.DEVICE, G.INTCON_B, 0)
>>> G.bus.write_byte_data(G.DEVICE, G.GPINTEN_B, 0xff)

but if I press any button (I have a button for each B pin ) and then I query the GPIO 7 pin, it always shows 0

What is interesting that before sending the above data to the mcp23017, the GPIO 7 pin shows 1, so it is connected correctly.

Maybe I am missing something.

I appreciate your help

Bob

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 7:19 am

bobvann wrote: So I bridged together INTA and INTB pins and connected to the GPIO 7 of the RPi.
Bob
How are you bridging these together - what would happen if A was high and B was low? My guess this may be your problem.

When you press the button (I'm guessing to simulate an interrupt), do you hold the button down? If not, the GPIO read could miss the button press - you need to use edge detection to spot the _change_ in an interrupt pin - something like GPIO.wait_for_event() does.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

bobvann
Posts: 4
Joined: Sat Sep 19, 2015 7:14 pm

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 7:35 am

Hi, thanks for the reply.

I am bridging them together simply by connectiong them phisically together and then to the gpio.

This is called cabled or, so if any of the two ones is high, the port should get high.

I am just pressing the button for something like a second.

The logic of the mcp23017 (as I read in the docs) is that if it detects a change in the state of the pin, it should pull high the interrupt pin untill you read the GPIO register. Then it should clear the register.

But the problem is that the interrupt seems not to be raising!


I will try to use wait_for_edge to see if it gives any instant interrupt instead of this logic, but the docs say that it stays high until you clear it

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 7:56 am

bobvann wrote: This is called cabled or, so if any of the two ones is high, the port should get high.
Does it work if you only connect the B interrupt to the GPIO pin - i.e. disconnect A from B?

Depending on how the interrupt pins are driven (open gate vs push pull) and how pull up down resistors on the GPIO pins and the chip are set, the A interrupt may be fighting with the B interrupt, and not result in any interrupt detected on the Raspberry Pi GPIO input pin.

If that doesn't work, then sorry, I have no other ideas.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

ghp
Posts: 1293
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 8:20 am

Hello,

I would NOT recommend to physically tie the two output pins together.

"The Open-Drain (ODR) control bit enables/disables the INT pin for open-drain configuration"
the two interrupt outputs may only be connected, if both of these pins are configured as open drain. You need a pullup then, the GPIO input could serve this. But be careful, after a reset this OCR-bit is not the default. And you need to carefully design your setup procedure. Problems here could damage the chip.

"Additionally, the INTn pins can be configured to mirror each other so that any interrupt will cause both pins to go active. This is controlled via IOCON.MIRROR"
This is the recommended operation if you do not want to connect each INTA,INTB-Pin to your controller. So connect only one, and set this bit in configuration.

Regards,
Gerhard

"Citations from mcp23017-datasheet."

bobvann
Posts: 4
Joined: Sat Sep 19, 2015 7:14 pm

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 9:32 am

Thanks for the answers.

I am trying right now to connect only one interrupt (the one I need) to the GPIO as disconnect the second, which may cause the problem.

I'm going to keep you updated.

bobvann
Posts: 4
Joined: Sat Sep 19, 2015 7:14 pm

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 1:17 pm

nothing....

I could not make interrupts work...

So I gave up, because I needed this thing urgently....and I decided to use a GPIO input and I will buy the RPi B+ which has 40 GPIO and remove the MCP23017

ghp
Posts: 1293
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: MCP23017 Interrupts not Raising

Sun Sep 20, 2015 2:03 pm

Perhaps it is needed to look for the buttons. How are your buttons connected to the Pins: (GPIO and GND) or (VCC and GPIO). Do you use external pullup or pulldown resistors ? Your init code does not show that you use the internal pullups by setting GPPUB.

The INTA output polarity is 'active low' by default, see IOCON.INTPOL, so when you get a low, the chip signals an event.

danjperron
Posts: 3281
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP23017 Interrupts not Raising

Thu Oct 01, 2015 2:54 pm

Are you sinking or sourcing your button?
You should sink them and set GPPA/B to 0xff for pull up resistor.

You should not connect intA and intB together. On reset they are set to be ttl output and one will short the other.Looks like that you didn't change the INT pin behavior. You need to set theI IOCON register.

Set IOCON.MIRROR to 1 and just use one INT pin.

P.S. on reset the INT pins are active low! Change IOCON.INTPOL to 1 for active high.

Massi
Posts: 1690
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: MCP23017 Interrupts not Raising

Thu Oct 01, 2015 3:26 pm

as said, the mirroring of INTA and INTB does not require hardware connection.
Than you have to configure the chip:
- only one edge or both edge (with mcp23017 this is done choosing if rise an interrupt when the level is different from a value set or when it changes)
- active high or low

Remember that when an interrupt is found, the interrupt pin will output it and will not change its state until you read the gpio values!

i have not under hand my code, but it seems to me that it's possible to have interrupt working on mcp :)

Return to “Interfacing (DSI, CSI, I2C, etc.)”