Main Site Documentation

CerbuinoBee Interrupt Input an EThernet Firmware


#1

Hello,
I am new to .NETMF , i have try to react to an input button with the simple code


       void ProgramStarted()
        {
  
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
            try
            {
                Debug.Print("Create Input BT Port");
                bt = new InputPort(GHI.Hardware.FEZCerb.Pin.PC0, false, Port.ResistorMode.PullUp);
                Debug.Print("Register BT Interrupt"); 
                bt.OnInterrupt += bt_OnInterrupt;
                Debug.Print("Enable BT Interrupt");
                bt.EnableInterrupt();
            }
            catch (Exception ex)
            {
                Debug.Print("Cant setup BT " + ex.Message);
            }
        }

        void bt_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print("Button press");
        }

I have try both Console Project or Gadgeteer but it fails with the follwing exception when adding the interrupt Handler:

Using mainboard GHI Electronics FEZCerbuinoBee version 1.2
Program Started
Create Input BT Port
Register BT Interrupt
Une exception de première chance de type ‘System.InvalidOperationException’ s’est produite dans Microsoft.SPOT.Hardware.dll
Une exception de première chance de type ‘System.InvalidOperationException’ s’est produite dans Microsoft.SPOT.Hardware.dll
Cant setup BT Exception was thrown: System.InvalidOperationException

the board is loaded with the last firmware 4.2.5 ethernet and have and ENC28 1.1
connected and pingable.
I also try other pin (PC1 PA4 ) without success


#2

Are you using a Gadgeteer project or a console project. From your code it looks like you are using a Gadgeteer project.

With a Gadgeteer project, you drag a button from the toolkit to the designer surface, and a variable for the button is automatically created for you. You then register an event.

If you want to manually create an object for a button, I would use the InterruptPort instead of the InputPort. I believe that GHI does not support interrupts with the InputPort class.


#3

many Thanks

replacing InputPort by InterruptPort as solved the problem

that is the difference between the two ?

Mike , even if it is a gadgeteer project I would not use a socket pour connecting by buton

because it is present on the aduino shield .

again thanks a lot


#4

What’s the difference between InputPort and InterruptPort? Well, one gives you a pin that you can then read when you want, and one you can assign an interrupt handler to in your code that will be called when it’s value changes. All interrupt capable pins can be used as digital input pins, but not all digital input pins are interrupt capable, so you need to make sure you’re firstly identifying them correctly, then using them correctly.


#5

It is a little bit confusing because we can also assign an interrupt Handler
to an inputPort.
and since on a cerbuino all input are interrupt capable.

that’s what I take an inputPort instead of InterruptPort .