Skip to content
Mike Schwager edited this page Oct 6, 2015 · 13 revisions

FAQ

  • The EnableInterrupt library does not work with
    • True, the library specifies the ISR's for all the Pin Change and External interrupt vectors.
Other libraries need some of these interrupts and define all of them as well. To handle this, you can disable some of the ISRs in the Enable Interrupt library by turning off the conflicting ISRs. See the SaveMemory wiki page. You may actually need to modify the code in the other library to remove ISRs that you need to use with the EnableInterrupt library. The Software Serial library (include the NewSoftwareSerial library), for one thing, ties up your processor with delays; furthermore, those delays are within its ISR. The ISR reads in the bits- and it reads an entire byte (including delays) before returning! This is a horrible practice for an interrupt routine. The AltSoftSerial uses the ATmega's timer circuitry. It is much, much friendlier to the CPU and allows your main program to run at times between serial signal transitions- which is most of the time during a serial data transmission.
    • Yeah but what is the downside of the AltSoftSerial library? It uses one of the ATmega's timers.
Other than that, I think its design is far superior.
  • I cannot include the EnableInterrupt library in my own library.
  • I cannot use the EnableInterrupt library with other code that uses the library.
Yes, yes you can. First some background: As you know, the C/C++ compiler allows you to separate your code into multiple files (which includes libraries). For example, your main sketch calls `setup()` and `loop()`, right? There is code in the Arduino software system (that is, the IDE that you use to write and upload your sketch) that tells your Arduino processor that it needs to call `setup` and `loop`, which you will define in your sketch. But the calling code is in a different place than your sketch, obviously (on my computer it's in the file `/usr/share/arduino/hardware/arduino/cores/arduino/main.cpp`). Since the multiple files are coded separately, they will be compiled separately. Before the Arduino IDE sends your program to the Arduino it then links all the needed files together.

Now, by default if you use the EnableInterrupt library in multiple files, then when the Arduino software gets to linking them, it discovers that certain functions (specifically the ISRs) have already been created. It complains because it would be an error to create another one; how is it to choose which function to really run?



It seems counterintuitive to compile the library's code twice; it makes no sense to us. Indeed, I have tried the `--read-my-mind` switch on the compiler. It says,

gcc: error: unrecognized command line option ‘--read-my-mind’
Drat; it doesn't work :-) . The compiler doesn't know that it makes no sense to compile code twice- it simply does what it's told. So, we have to be careful to tell the compiler *exactly* what to do. Therefore, you must insert
#define LIBCALL_ENABLEINTERRUPT
in front of every `#include ` in every one of the files in which you want to use EnableInterrupt library functionality- *except one*. In that file (often but not necessarily your sketch), just place the `#include` directive; don't define the `LIBCALL_ENABLEINTERRUPT`. Then for that one file only the compiler will create the Arduino code and it will then link all references to its functions as necessary. The compiler is no longer confused since there is only one set of compiled code for the library.
  • I want to use the EnableInterrupt library to interrupt on Analog signals.
    • Sorry, that's not supported by the Arduino's interrupt system.
  • I want to attach multiple function to a single pin.
    • Sorry, only 1 function per pin. If you need to call multiple functions then just have your
function call the other functions.
Clone this wiki locally