8 Replies Latest reply on Mar 10, 2016 9:41 AM by maestr0

    Edison ISR

    Madhura!

      I have trying to use one of the GPIO pins on Edison board as an external interrupt. Please have a look at the code:

       

      var mraa = require('mraa');

      var InterruptPin = new mraa.Gpio(7);

      InterruptPin.dir(mraa.DIR_IN);

      InterruptPin.isr(mraa.EDGE_BOTH, a());

       

      function a() {

          console.log("Yo!!");

      }

       

      In such a simple code above, the program never comes out of the ISR. It displays 'Yo!' only once and then never senses any changes on pin 7. Am I missing out on something important? And what does isrExit exactly do?

       

      Thanks & Regards

        • 1. Re: Edison ISR
          DiegoV_Intel

          Hello Madhura!,

           

          Have you checked the examples available here: mraa/examples at master · intel-iot-devkit/mraa · GitHub? You will find examples about the ISR using Python, C++ and JavaScript. I've tested the Python example and it worked.

           

          According to the MRAA documentation, the isrExit() method is an exit callback. Please check the full description here:

          mraa: Gpio Class Reference

           

          Regards,

          Diego.

          • 2. Re: Edison ISR
            Madhura!

            Thanks a lot DiegoV_Intel for your reply. I tried out the examples given at the link you mentioned.

             

            However, with the example given,  mraa/isr.js at master · intel-iot-devkit/mraa · GitHub

            the program enters in the ISR only at the beginning, and it never goes into the ISR again. Same is the case with the sample project for ISR provided with XDK.

             

            The board is handling external interrupts perfectly while working in Arduino IDE. So, I don't really understand now what's going wrong when working with XDK. Has anyone ever encountered the same problem?

             

            Thanks & Regards,

            Madhura

            • 3. Re: Edison ISR
              Sriranjan

              Hi Madhura,

               

              You mentioned that you were able to use external interrupts in Arduino IDE. How are you doing this.Could you help me with the code for external interrupts in Arduino IDE?Does it meen you are able to use MRAA library in arduino?I am just beginning things with the edison.

              • 4. Re: Edison ISR
                DiegoV_Intel

                Hello Madhura!,

                 

                Could you please try to run the following code and confirm if it works for you? This sample code hasn’t been validated yet but it might work properly.

                 

                #!/usr/bin/env node
                
                var mraa = require('mraa') //require mraa
                console.log('MRAA Version: ' + mraa.getVersion()); //write mraa version to the console
                
                function h()
                {
                console.log("Yo!!") //write message to the console
                }
                
                InterruptPin = new mraa.Gpio(7) // mraa7 - gp20
                InterruptPin.dir(mraa.DIR_IN) //set the Gpio direction to input
                a(); //call the a function
                
                function a()
                {
                InterruptPin.isr(mraa.EDGE_BOTH, h)
                setTimeout(a, 500); // call the a function after 500 millis
                }
                

                 

                Regards,

                Diego.

                • 5. Re: Edison ISR
                  Madhura!

                  Thanks a lot DiegoV_Intel!!

                  The program is working perfectly now.. I had not declared the InterruptPin.isr(mraa.EDGE_BOTH,h)  inside a function, hence the program control was going inside the ISR only once.

                   

                  Hey Sriranjan! Find attached a simple ISR code for testing in Arduino. I am not using mraa library inside Arduino. Instead using the 'attachInterrupt' function. Hope it helps you.

                   

                  Thanks & Regards,

                  Madhura

                  • 6. Re: Edison ISR
                    Sriranjan

                    I have to work with an external clock interrupt at 11 mhz but generate the ISR from this interrupt at 44 khz. In ARM I did rc = 11111111/256 and my ISR runs at 44 khz. How shall I do the same here? Please let me know.Also I need the interrupt on rising edge not both (how shall I set it to rising edge?).

                    • 7. Re: Edison ISR
                      Propst

                      @Madhura!, you should not need to put the isr call within another function. In fact, that will cause it to unnecessarily be called over and over.

                      The bug in your original code was simply that you included the parenthesis after the ISR function handle. That is also why it was being called initially, presumably when no interrupt actually happened.

                      I'm only replying late to this topic because I just saw the same bug.

                      • 8. Re: Edison ISR
                        maestr0

                        @Madhura!

                         

                        This is a working ISR example.

                         

                        var mraa = require('mraa');
                        var InterruptPin = new mraa.Gpio(8);
                        
                        
                        function myCallback() {
                            console.log("Yo!!");
                        }
                        
                        
                        // set GPIO 8 as input
                        InterruptPin.dir(mraa.DIR_IN); 
                        
                        /* 
                             EDGE_BOTH means EITHER 0->1    or 1->0 transition,  
                             NOTICE that myCallback has no ()
                        */
                        InterruptPin.isr(mraa.EDGE_BOTH, myCallback); 
                        
                        
                        
                        
                        // this is meant to keep the node process running all the time!
                        
                        setInterval(function(){
                            console.log("I'm alive");
                        },1000);
                        
                        console.log("start");