InterruptPort behaviour

Just a quick question, is this the correct behaviour for interruptPort on FEZ Spider

Button (1.3) plugged into socket 8.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace GadgeteerApp2
    public partial class Program
        private InterruptPort port = null;

        void ProgramStarted()
            port = new InterruptPort((Cpu.Pin)30, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            port.OnInterrupt += new NativeEventHandler(_port_OnInterrupt);

            Debug.Print("\r\n*** Button Test ***");

        private void _port_OnInterrupt(uint port, uint state, DateTime time)

The value of state is always 1 on button press and release.
I was wondering why does does it not change on rising/falling edge triggers?
I tried this on a Domino and got the same result, tried it on a netduino and it toggles between 1 and 0.



How did you determine that you were attaching to pin 30 of the CPU chip?

I assume you are using an extender socket for attaching the signal.

Use the graphic designed to define the extender module.

Then define the interrupt port using the SetupInterruptInput() method of the extender reference.

Even if you are not using an extender module, attaching directly to the socket, lie and say you are using an extender module. :slight_smile:

Just noticed you are using a button. Is it a button module? If so, why not just define the button in the graphic designer? Also with a mechanical button you would want to turn the glitch filter on.

Your code doesn’t use the gadgeteer libraries. It will be very difficult to use gadgeteer board the way you are doing it (pure NETMF)

@ Gus - This code was purely to isolate another issue. Button->InterruptInput->InterruptPort. I just wanted to know why it worked as it does.

@ Mike - Found the pin in the source, I know I have the right one for this test, I wouldn’t do this in real code.

If you are using a GHI Gadgeteer button module have you applied the patch?

There is no patch anymore. You need the SDK listed in beta forum.

Yep, the Beta SDK’s Button ignores the value from InterruptPort’s OnInterrupt and adds it’s own Input.Read() call in it’s handlers.

But the question I was asking was only, is it correct that the state value is always 1, which seems to contradict the msdn docs.

I am lost. What exactly are you trying to do?

The button with the driver provided works just fine. Right?

I just wanted to know if there is a reason that the State parameter on the OnInterrupt event of InterruptPort is always 1.

MSDN reads: state - A value that specifies whether the GPIO pin state is 0 (zero) or 1.

I don’t have a problem to solve, just the above question.

It is due to a capacitor on the button module. Remove it and it will work fine.

I guess this is just the lack of my electronics knowledge, but I thought that the interrupt would fire off a level transision on the GPIO pin, so why would the fact that there is a cap on the button have an effect? I’m assuming that the native interrupt handler fires and the pin is sampled in the handler, rather than relying on the status registers that show if it was a rising or falling edge?


I think I ran into the same problem.
Using the FEZ domino ( I stripped down my problem to:

I use this code to react on the changing levels of Di0:

            InterruptPort input = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.Di0, false, Port.ResistorMode.PullDown , Port.InterruptMode.InterruptEdgeBoth);
            input.OnInterrupt += new NativeEventHandler(input_OnInterrupt);

If I am not mistaken all I need to do to get the interrupt to fire is to connect Di0 to the 5v or 3.3v on the board and to remove the connection again. The internal pulldown circuit will take care to the rest.

When I do this most of the time the data2 parameter of input_OnInterrupt is 1. Sometimes it is 0 for a small period of time but only during the removing or attaching of the wire, at rest (connected or disconnected) it is alway 1.

This is unrated to what you are doing.

Welcome to the community