Passing arguments to interrupts?

Hi everyone,

I am now on the last leg of my library for a trip computer I have been working on for my car. The only thing holding me back now is that I cannot seem to pass a pointer to an interrupt I have made in my library. Does anyone know if its even possible to pass arguments to an interrupt function? Basically what I am looking to do is add 1 to a pointer to an int I have defined in my main program.

this is in my setup function in the main program: attachInterrupt(0, vor, FALLING);

and the prototype for vor is : void vor(volatile int *function);

I have tried calling : attachInterrupt(0, vor(&function), FALLING);
too, but they both always return the error vor was not declared in this way.

FYI: volatile int function = 1; is declared before the setup() function in my main code window.

If you need the complete code, please let me know and I will post a link, but I guess this is more of a general question.

Thanks in advance.

Can't pass any kind of parameter to an interrupt.
Think of how an interrupt happens, and you'll see why.

Thank you for the quick reply AWOL. In case anyone was wondering, I got around this by not defining the interrupt in my library, but instead creating the function in my main program and declaring the variable I wanted to change as a global variable.

Just curious. Are memory writes indivisible such that the whole address is written before the interrupt routine is called?

Just curious. Are memory writes indivisible such that the whole address is written before the interrupt routine is called?

If you are referring to a possible 'atomic' problem, then no, there is no protection of the main sketch trying to read a int value and having an interrupt corrupt the value after just one byte has been updated and then a interrupt triggers that changes the same variable. One needs to bracket any int or larger value used in a statement with noInterrups() and interrupt() statements to protect from that possible and hard to figure out problem. If you are using byte variables then that is not required.

http://arduino.cc/en/Reference/Interrupts

Lefty

Tis' what I thought and wanted firestork and others to be aware of!