Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Win 10 IOT Interrupt Query

The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi

20/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Hi,

I'm looking at the documentation here: https://github.com/abelectronicsuk/ABElectronics_Win10IOT_Libraries/tree/master/ABElectronics_Win10IOT_Libraries

Particularly this:



ReadInterruptStatus(byte port)


Enable interrupts for the selected pin <---- I'm guessing this is a typo
Parameters: port 0 = pins 1 to 8, port 1 = pins 8 to 16
Returns: status


ReadInterruptCapture(byte port)


Read the value from the selected port at the time of the last interrupt trigger
Parameters: port 0 = pins 1 to 8, port 1 = pins 8 to 16
Returns: status



What I could do with is some sort of example on how this works.

I have configured it so that the INT ports are mirrored and trigger a GPIO interrupt.

I presume I use one of the above commands to read the port status (so would then have to write a function to split it down to individual pin states).

Has anyone managed to achieve this and could give me some basic pointers on using these commands?

Thanks,

Richie

20/10/2017

Posted by:
andrew

andrew Avatar

Hi Richie

We don't have any Windows 10 demos for the interrupts at the moment but we do have a Python version which would be easy to translate to C# as the function names are almost the same as the C# version.

You start by setting the interrupt polarity and whether you want the two interrupt pins to be mirrored or show the status of each port. This is done with the SetInterruptPolarity() and MirrorInterrupts() functions.

Next, you set the default values on which the interrupt would be triggered so for example if you only want to trigger an interrupt for pin 1 when it goes high you would use SetInterruptDefaults(0, 0x01).

The SetInterruptType() function sets whether the interrupt fires when it matches the default value or when the pin state changes.

The final part of the setup is the SetInterruptOnPin() and SetInterruptOnPort() functions which configure which pins the interrupts will monitor.

With the setup complete you can call the ReadInterruptCapture() function at regular intervals to see if an interrupt has been triggered. The ReadInterruptCapture() will return a value of 0 if no interrupts have been triggered otherwise it will show a number for the port value. The number is between 0 and 255 so for example if pin 4 triggered the interrupt it would return a value of 8 while pin 7 would return a value of 64.

Hopefully, the python demo will be enough to get you started with the interrupt functions but if you have any other questions please let me know.

21/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Ok, so I'm thinking of something like the following:

IOx32_bus1.MirrorInterrupts(1); - both ports trigger both interrupt pins
IOx32_bus1.SetInterruptPolarity(1); - interrupt pin goes from low to high
IOx32_bus1.SetInterruptType(0, 0); - interrupt triggers when pin state changes (either 0 to 1 or 1 to 0)
IOx32_bus1.SetInterruptType(1, 0);

IOx32_bus1.SetInterruptOnPin(intPinNumber, false); - sets the specified pin as interrupt enabled

I'm then linking the interrupt pin to a GPIO pin, which calls a function when triggered that will do the following:

IOx32_bus1.ReadInterruptCapture(0 or 1) --> binary string, reversed and converted to a bool array.

I will then have something like boolarray[element2] = pin2 interrupt status (so would be true if pin 2 had changed state).

I can then read pin2 to get its new value.



Would that work?



Thanks,

Richie

22/10/2017

Posted by:
andrew

andrew Avatar

Hi Richie

IOx32_bus1.SetInterruptOnPin(intPinNumber, false); needs to be IOx32_bus1.SetInterruptOnPin(intPinNumber, true);

There was an error in the documentation which I have fixed. You need to set the pin to be true to enable the interrupt, not false like it said in the documentation.

Apart from that, your code should work.

27/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Hi,
Thanks for your help - I'm getting somewhere now, but still having some issues.
I can read inputs ok and, when I change an input state, I can read which input changed from:
ReadInterruptStatus(0) and ReadInterruptStatus(1).
However, the INT output pins never change state.
I currently have:
MirrorInterrupts(1);
SetInterruptPolarity(0);
SetInterruptType(0, 0);
SetInterruptType(1, 0);
SetInterruptOnPin(, true);

The INT output is connected to a GPIO pin, which remains permanently low (or high if I set SetInterruptPolarity(1)).
I presume I'm still missing something somewhere.

I am wondering whether I need to use this command, but not sure how as I am wanting the INT pin to trigger on input going 0 to 1 or 1 to 0:



SetInterruptDefaults(byte port, byte value)


These bits set the compare value for pins configured for interrupt-on-change on the selected port.
If the associated pin level is the opposite from the register bit, an interrupt occurs.
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16, value: compare value
Returns: null



Thanks,
Richie

27/10/2017

Posted by:
andrew

andrew Avatar

Hi Richie

You will need to call the ReadInterruptCapture(byte port) or ResetInterrupts() functions to reset the status of the interrupt once you have read the value. The ReadInterruptStatus() function does not call the reset so without calling one of the other two functions the INT output will not change back to its default value.

27/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Hi,

Yes, I understand that, but the issue I'm having is that the INT pins are NOT changing state on an input change (even though ReadInterruptStatus(0 or 1) returns the correct triggered pin). So, at the moment, I have no way of raising an interrupt that can be picked up in code - I would prefer not to have to keep polling the ReadInterruptStatus every 100ms or more.

Thanks,
Richie

27/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Hi,

I've found some info here http://www.microchip.com/forums/m701978.aspx

It says the the interrupt pins need to be set to "Open Drain" and use pull ups.

I've set the Raspberry Pi GPIO pin to input Pull Up, but how do I set the IO interrupt pin to Open Drain?

Thanks,
Richie

27/10/2017

Posted by:
andrew

andrew Avatar

Hi Richie

The Windows 10 library didn't have the ability to set the interrupt pins as open drain so I have added a new function called SetInterruptOutputType(byte value) to the IO Pi class.

It takes one parameter which can be 1 or 0. 1 will set the interrupt pins to be open drain while 0 will set them to be an active driver.

You can download the new version from GitHub at ABElectronics UK Windows 10 IOT Libraries.

27/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Wow, fast service :)

I've updated your library via NuGet just now, but will not be able to test until tonight when I am back at home where my Raspberry Pi is.

I am hoping this should resolve the issue and will update you when tested.

Thanks,
Richie

27/10/2017

Posted by:
RichieRogers

RichieRogers Avatar

Just tried it and it works - I can now pick up interrupts. I get errors now in my interrupr event handling, but that's my code not yours causing it :)

Thanks for your help and speedy resolution

Richie

Sign in to post your reply


Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout