Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MGand1
Novice
1,869 Views

Edison ISR

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

8 Replies
Diego_V_Intel
Employee
92 Views

Hello Madhura!,

Have you checked the examples available here: https://github.com/intel-iot-devkit/mraa/tree/master/examples 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:

http://iotdk.intel.com/docs/master/mraa/classmraa_1_1_gpio.html# a6c4af539f1e488a78b811dbbd43ad014 mraa: Gpio Class Reference

Regards,

Diego.

MGand1
Novice
92 Views

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

However, with the example given, https://github.com/intel-iot-devkit/mraa/blob/master/examples/javascript/isr.js 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

SRasa
Valued Contributor I
92 Views

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.

Diego_V_Intel
Employee
92 Views

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.

MGand1
Novice
92 Views

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

SRasa
Valued Contributor I
92 Views

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?).

THOMAS_P_Intel1
Employee
92 Views

@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.

idata
Community Manager
92 Views

@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");

Reply