[Solved] Interrupt on FEZ Cerberus

Hello,

I have a curious issue: a button is connect on socket 7, and a breadboard on socket 6. I test interrupt with the button on breadboard (wired to pin3). Interrupt works perfectly.
The button on socket 7 raise the interrupt (but just on falling edge): why ?

I must forget something, but I can find it !


public partial class Program
    {
        private bool _bMainboardLed;
        private bool _bBreadBoardLed;
        private DigitalOutput _doBreadboardLed;
        private InterruptInput _iiBreadbordButton;
        private InterruptPort _breadboardButtonInterruptPort;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            _bMainboardLed = false;
            Mainboard.SetDebugLED(_bMainboardLed);
            Debug.Print("Program Started");

            // Configure button behavior
            button.Mode=Button.LedMode.OnWhilePressed;
            button.ButtonPressed += button_ButtonPressed;

            // Configure Breadboard Input/Output
            _bBreadBoardLed = false;
            // Led connected on port 4 as digital output
            _doBreadboardLed = breadBoardX1.CreateDigitalOutput(GT.Socket.Pin.Four, _bBreadBoardLed);
            // Button connected on port 3 as digital input/interruption
            _iiBreadbordButton = breadBoardX1.CreateInterruptInput(GT.Socket.Pin.Three, GlitchFilterMode.On, ResistorMode.PullUp,
                InterruptMode.RisingAndFallingEdge);
            _iiBreadbordButton.Interrupt += _iiBreadbordButton_Interrupt;

            FlashMainboardLed();
        }

        void _iiBreadbordButton_Interrupt(InterruptInput sender, bool value)
        {
                Debug.Print(sender.ToString()+","+value);
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            _doBreadboardLed.Write(!_doBreadboardLed.Read());
        }

        private void FlashMainboardLed()
        {
            var tMainboard = new Thread(() =>
            {
                for (int i = 0; i < 5; i++)
                {
                    _bMainboardLed = !_bMainboardLed;
                    Mainboard.SetDebugLED(_bMainboardLed);
                    Thread.Sleep(100);
                }
            });
            tMainboard.Start();
        }
    }

When something does not work as expected in Gadgeteer, the answer can often be found by reading the Gadgeteer source code. It took me about 20 seconds to find the answer.

In native MF, you can have your interrupt handler called on rising and falling edges, which corresponds to press and release of the button.

But, with the Gadgeteer button handler, the press and release interrupts are separate. You have registered for button pressed, which you are receiving. If you want an interrupt when the button is released, you need to register for ButtonReleased.

But the button connected on socket 7 shouldn’t raise the interrupt !!! Only the button on breadboard (pin 3) should raise it…

You have requested an interrupt with the following statement



I assume the button is connected to socket 7/
1 Like

Do I say a mistake when I say:
[ul]Button on socket 6 (pin3) should only fire [em]_iiBreadbordButton_Interrupt[/em]
Button on socket 7 (pin3) should only fire [em]button_ButtonPressed[/em]
[/ul]

But button on socket 7 (pin3) raise [em]_iiBreadbordButton_Interrupt[/em] too !

Cerberus shares interrupts so that may be coming into play. I think the way to test this is to reverse the definition of your interrupt handlers and see if the called interrupt moves to the other handler - which means it is definitely the shared interrupt that’s causing you an issue. To address that you might swap to a different pin on the breadboard module (apparently all pins are interrupt capable, it’s only pin3 on a Gadgeteer socket that is guaranteed to be capable)

One more step: the line which causes issue was …



Now I must understand why !!!! :wall:

Found it : I’m an idiot !

On breadboard switch must be configured to PullDown and not PullUp…