Use interrupt with IO60P16 module

hello, I debuted with my Fez Hydra board and module IO60P16, I waited impatiently for the interrupt function is present in the new GHI SDK 4.2, now it’s ok I’m just trying to trigger using a switch but I can not do it, I put a pull up ais 10k between input and V + with the following code :

io60p16.CreateInterruptPort(IOPin.Port4_Pin1);
io60p16.Interrupt += (sender, args) => Debug.Print("Port: " + args.Port + " Pin: " + args.Pin );

, but when I press the swicht I board the following result:
Port: 0 Pin: 0
Port: 0 Pin: 1
Port: 0 Pin: 2
Port: 0 Pin: 3
Port: 0 Pin: 4
Port: 0 Pin: 5
Port: 0 Pin: 6
Port: 0 Pin: 7
Port: 1 Pin: 0
Port: 1 Pin: 1
Port: 1 Pin: 2
Port: 1 Pin: 3
Port: 1 Pin: 4
Port: 1 Pin: 5
Port: 1 Pin: 6
Port: 1 Pin: 7
Port: 2 Pin: 0
Port: 2 Pin: 1
Port: 2 Pin: 2
Port: 2 Pin: 3
Port: 2 Pin: 4
Port: 2 Pin: 5
Port: 2 Pin: 6
Port: 2 Pin: 7
Port: 3 Pin: 0
Port: 3 Pin: 1
Port: 3 Pin: 2
Port: 3 Pin: 3
Port: 3 Pin: 4
Port: 3 Pin: 5
Port: 3 Pin: 6
Port: 3 Pin: 7
Port: 4 Pin: 0

Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1)

Message:

Gadgeteer.Modules.GHIElectronics.ModulePort::OnParentInterrupt [IP: 0027]

Gadgeteer.Modules.GHIElectronics.IO60P16+InterruptEventHandler::Invoke [IP: 20df9abc]

Gadgeteer.Modules.GHIElectronics.IO60P16::OnInterrupt [IP: 0037]

Gadgeteer.Interfaces.InterruptInput::OnInterruptEvent [IP: 0055]

System.Reflection.MethodBase::Invoke [IP: 0000]

Gadgeteer.Program::DoOperation [IP: 001a]

Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054]

Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a]

Microsoft.SPOT.Dispatcher::Run [IP: 0006]

Gadgeteer.Program::Run [IP: 0020]

Une exception de première chance de type ‘System.NullReferenceException’ s’est produite dans GTM.GHIElectronics.IO60P16.dll
Error invoking method “Gadgeteer.Interfaces.InterruptInput” (check arguments to Program.BeginInvoke are correct)
Le programme ‘[23] Micro Framework application: Managé’ s’est arrêté avec le code 0 (0x0).

my firmware Version: 4.2.3.0

if anyone can help me

Can you please show the complete code?

Also, are you using the latest 4.2 SDK? Support – GHI Electronics

yes it is the GHI NETMF v4.1 v4.2 and .NET Gadgeteer Package (RC2 8-24-2012)

my test code :

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp17
{
    
    public partial class Program
    
    {
        
        // 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.
            Debug.Print("Program Started");
            io60p16.CreateInterruptPort(IOPin.Port4_Pin1);
            io60p16.Interrupt += (sender, args) => Debug.Print("Port: " + args.Port + "  Pin: " + args.Pin );
         

      
        
        }

      

    }
}

@ gnomathibus - it seems that a bug is present in port.cs file of the driver, function OnParentInterrupt. The call doesn’t check if a null callback is attached to event ( so no event handler). I’m wrting from the phone and can’t show code.
If you have patience check the whole thread for io60p16, you can find a description of the code problem.

ok thank you for your reply Dobova, so no solution yet?

From what he is saying, add an even handler and it would work. Why would you need interrupt pin if there is no event handler anyway?

I’m sorry for delay, but I got trouble with 3G connection.
Anyway, I’ve to discuss with Ian about this issue, we discovered weeks ago.
To make it easy, try to use IO60P16.InterruptPort class:


...
            Gadgeteer.Modules.GHIElectronics.IO60P16.InterruptPort iport;
...

            iport = new GTM.GHIElectronics.IO60P16.InterruptPort(io60p16, IOPin.Port4_Pin1);
            iport.ClearInterrupt();
            iport.OnInterrupt += (port, pin, time) =>
                {                    
                    Debug.Print("Port: " + port + "  Pin: " + pin);
                    iport.ClearInterrupt();
                };


Be aware that this call mimic netmf InterruptPort behaviour, and take care that event handler has different parameters.
Let us know if this works for you. Thanks

thank you very much for your help Dobova, sorry for my inexperience I noobs,
I tried your code above with the new SDK 4.2 it gives me this:

            
...
     GTM.GHIElectronics.ModuleInterruptPort iport;
...         

            iport = new GTM.GHIElectronics.ModuleInterruptPort(io60p16, IOPin.Port4_Pin1); 
            iport.ClearInterrupt();
            iport.OnInterrupt += (port, pin, time) =>
                   {
                         Debug.Print("Port: " + port + "  Pin: " + pin );
                         iport.ClearInterrupt();
                   };
    

When I press my switch I get the following result well in Debuger: Port: 4 Pin: 1 :slight_smile:

but if I press the switch again nothing happens even after a new deployment of the program, I noticed that I have to unplug the USB cable and reconnect again I make it work

I think that for some reason, the Int pin doesn’t reset with ClearInterrupt() call. I’m updating Hydra to new firmaware and than I will check.
But Murphy law is on the way of my hydra and I can’t successful update …

ok I’m waiting for your result

Actually, the intended usage should look like this…


...
            Gadgeteer.Modules.GHIElectronics.IO60P16.InterruptPort iport;
...

            iport = io60p16.CreateInterruptPort(IOPin.Port4_Pin1);
            iport.OnInterrupt += (port, pin, time) =>
                {                    
                    Debug.Print("Port: " + port + "  Pin: " + pin);
                };


But, I don’t suspect you’re going to get a different result but it’s worth trying. You really shouldn’t ever have to call ClearInterrupt() manually. I’ll start working on the tutorial for this module next week after I return from DevLink. There were some known issues in the code I handed over to GHI to include in the last SDK release. I’m not sure how much they were able to fix, if any, before release. This will give me a chance to run through those and fully documented the intended usages.

@ Gus, it doesn’t look like the current driver code is in CodePlex. Can you try and get that updated sometime this week so I can see what you ended up delivering?

Hi Ian … Sure… I forgot about the interruptport creator, but should be fine in both ways.

@ gnomathibus: finally I got Hydra updated (weird USB problems with new vmware workstation 9 installed).

Using port 1, bit 0: I’ve no problem with INT…


Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0
Port: 1  Pin: 0

This is the result of looping thread (300ms delay) driving port1,bit0 input. If you look in the attached image, you can see the topmost INT line (yellow) and the driving signal in the lowest green line. At any change of the green line (go high, go low) you see a yellow spike on INT pin.

@ Ianlee - at the moment I don’t see any call to the clear interrupt register. This can be inserted (troughout OnParentInterrupt()) in the Port.cs, so any time an int is served, the bit is cleared.

Hmm… Actually, I thought we were clearing in IO60P16Module.OnInterrupt after the loop was finished and all the individual events were fired. It looks like this was overlooked. I think this would be the better place to do this rather than try and have each pin send a separate clear.

@ ianlee74 : you are right, it will be a big mistake my idea, shame on me! … the clearing is at port level ! So if you need more bit on the same port you miss all other !

[quote]@ gnomathibus: finally I got Hydra updated (weird USB problems with new vmware workstation 9 installed).

Using port 1, bit 0: I’ve no problem with INT…

Port: 1 Pin: 0
Port: 1 Pin: 0
Port: 1 Pin: 0
Port: 1 Pin: 0
Port: 1 Pin: 0[/quote]

I tested again and I can not understand why the interrupt is triggered only once after my module IO60P16 and nothing more, as if the connection was lost, I have to unplug the USB cable and the plug it in again before deploying the program, I have two modules io60p16 and this is the same problem :frowning:

@ gnomathibus - it would appear that the interrupt register is not being cleared after the first interrupt is fired. Although, I don’t recall ever encountering this during testing. Unfortunately, I’m out of town the rest of the week and won’t be able to try and reproduce your problem until next week. Perhaps dobova or someone at GHI can look into it. Otherwise, I’ll look at it next week when I start on the tutorials.

@ gnomathibus :
Just to be sure, are you using last NetMf QFE2, last SDK from GHI and last firmware for Hydra ?
My test was done with IO60P16 board on Hydra socket 6, using Port1, pin0, last Ian’s driver from codeplex. I will try later on other port.

I checked Ian’s driver code and the INT clear call is there, so I can’t figure out the problem.

Other thing you can try: change the power supply method you are using: if using external PS switch to USB power or viceversa.

I continued my investigation of my problem, I just tried the driver netmfx-18409 and it is a little better then the switch and the following code:

...
            Gadgeteer.Modules.GHIElectronics.IO60P16.InterruptPort iport;
...
 
            iport = new GTM.GHIElectronics.IO60P16.InterruptPort(io60p16, IOPin.Port4_Pin1);
            iport.ClearInterrupt();
            iport.OnInterrupt += (port, pin, time) =>
                {                    
                    Debug.Print("Port: " + port + "  Pin: " + pin);
                    iport.ClearInterrupt();
                };

I have the following result:
Port: 4 Pin: 1
Port: 4 Pin: 1
Port: 4 Pin: 1
Port: 4 Pin: 1
Port: 4 Pin: 1
Port: 4 Pin: 1

after the fourth or fifth interruption it happens nothing when I press the switch

With a cable between two pine and the following code:


   io60p16.SetDirection(IOPin.Port4_Pin1, PinDirection.Output);
            io60p16.SetDirection(IOPin.Port1_Pin0, PinDirection.Input);
            io60p16.SetInterruptEnable(IOPin.Port1_Pin0, true);
            io60p16.Interrupt += (sender, args) => Debug.Print("Port: " + args.Port + "  Pin: " + args.Pin);
            var timer2 = new GT.Timer(200);
            timer2.Tick += timer1 =>
            {
                io60p16.Write(IOPin.Port4_Pin1, false);
                Thread.Sleep(20);
                io60p16.Write(IOPin.Port4_Pin1, true);
            };
            timer2.Start();

I have the following result and crashes:

Port: 2 Pin: 0
Port: 2 Pin: 1
Port: 2 Pin: 2
Port: 2 Pin: 3
Port: 2 Pin: 4
Port: 2 Pin: 5
Port: 2 Pin: 6
Port: 2 Pin: 7
Port: 6 Pin: 0
Port: 6 Pin: 1
Port: 6 Pin: 2
Port: 6 Pin: 3
Port: 6 Pin: 4
Port: 6 Pin: 5
Port: 6 Pin: 6
Port: 6 Pin: 7
Port: 7 Pin: 0
Port: 7 Pin: 1
Port: 7 Pin: 2
Port: 7 Pin: 3
Port: 7 Pin: 4
Port: 7 Pin: 5
Port: 7 Pin: 6
Port: 7 Pin: 7
Port: 0 Pin: 0
Port: 0 Pin: 1
Port: 0 Pin: 2
Port: 0 Pin: 3
Port: 0 Pin: 4
Port: 0 Pin: 5
Port: 0 Pin: 6
Port: 0 Pin: 7
Port: 1 Pin: 0
Port: 3 Pin: 0
Port: 3 Pin: 1
Port: 3 Pin: 2
Port: 3 Pin: 3
Port: 3 Pin: 4
Port: 3 Pin: 5
Port: 3 Pin: 6
Port: 3 Pin: 7
Port: 4 Pin: 0
Port: 4 Pin: 1
Port: 4 Pin: 2
Port: 4 Pin: 3
Port: 4 Pin: 4
Port: 4 Pin: 5
Port: 4 Pin: 6
Port: 4 Pin: 7
Port: 7 Pin: 0
Port: 7 Pin: 1
Port: 7 Pin: 2
Port: 7 Pin: 3
Port: 7 Pin: 4
Port: 7 Pin: 5
Port: 7 Pin: 6
Port: 7 Pin: 7
Port: 0 Pin: 0
Port: 0 Pin: 1
Port: 0 Pin: 2
Port: 0 Pin: 3
Port: 0 Pin: 4
Port: 0 Pin: 5
Port: 0 Pin: 6
Port: 0 Pin: 7
Port: 1 Pin: 0
Port: 2 Pin: 0
Port: 2 Pin: 1
Port: 2 Pin: 2
Port: 2 Pin: 3
Port: 2 Pin: 4
Port: 2 Pin: 5
Port: 2 Pin: 6
Port: 2 Pin: 7
Port: 3 Pin: 0
Port: 3 Pin: 1
Port: 3 Pin: 2
Port: 3 Pin: 3
Port: 3 Pin: 4
Port: 3 Pin: 5
Port: 3 Pin: 6
Port: 3 Pin: 7
Port: 5 Pin: 0
Port: 5 Pin: 1
Port: 5 Pin: 2
Port: 5 Pin: 3
Port: 5 Pin: 4
Port: 5 Pin: 5
Port: 5 Pin: 6
Port: 5 Pin: 7
Port: 7 Pin: 0
Port: 7 Pin: 1
Port: 7 Pin: 2
Port: 7 Pin: 3
Port: 7 Pin: 4
Port: 7 Pin: 5
Port: 7 Pin: 6
Port: 7 Pin: 7
Port: 0 Pin: 0
Port: 0 Pin: 1
Port: 0 Pin: 2
Port: 0 Pin: 3
Port: 0 Pin: 4
Port: 0 Pin: 5
Port: 0 Pin: 6
Port: 0 Pin: 7

Not normal I think I should have:
Port: 1 Pin: 0
Port: 1 Pin: 0
Port: 1 Pin: 0
Port: 1 Pin: 0 …

if it can be useful I use mode softwarei2c

Someone did he do new tests for my problem with interrupt function ?

Thanks for the reminder. I’m back from traveling and will take a look this evening.

EDIT: I ended up spending all night working on the dishwasher instead of the fun stuff I had planned :frowning: I’ll try again tonight.