As of Arduino 1.0, interrupts are not supported on the Arduino Leonardo. I’m working on a project using the atmega32u4 with the Arduino IDE which needs interrupt support for both software serial and frequency counting, so I investigated ways to add interrupt support for this device. I began by checking out the Leonardo pins definition file to see what was missing for interrupt support. Long story short, I ended up copying the macros for interrupt bitmasks/registers from the Teensyduino project, which has a mega32u4 target board. In addition to modifying the pin definition header file, I also needed to modify WInterrupts.c—swapping out the default AttachInterrupt() and DetachInterrupt() funcitons with those from the Teensyduino project.
I have included links below to the pin definition header file and interrupt functions in my project repository. Place these files in the hardware/arduino/core and hardware/arduino/variants/leonardo folders. Note that my current revision of these files only support the m32u4, interrupt support for other devices is broken. You can throw some #ifdefs in there and include the existing code to support devices other than the m32u4, I will hopefully get around to adding this in the coming weeks.
I also want to get SoftwareSerial up and running on the m32u4; I’ll be looking into the Teensyduino variant of NewSoftSerial this week, check back for more updates in the coming days.
Update: The Arduino team has successfully implemented interrupts.
Hi,
Is there any update or ETA for softwareserial with the Leonardo? Thanks.
I’ve “hacked” SoftwareSerial into a working state, but it’s not pretty. Basically you have to add an attachInterrupt(myRxPin, myTestISR, CHANGE) call in your setup() which calls an ISR you write. The ISR you write should call mySoftwareSerialInstance.recv() which I made public. Nasty, but it works. Let me know if you try it out / have any better ideas. I couldn’t get attachInterrupt() to work on a method of a class, which is why I’m doing it externally.
Main test file (line 49, 61 of interest): http://protofusion.org/hg/supermileage/file/271c53e52125/Arduino/SuperMileage/SuperMileage.ino
Modified SoftwareSerial library:
http://protofusion.org/hg/supermileage/raw-diff/271c53e52125/Arduino/Libraries/SoftwareSerial/SoftwareSerial.cpp
http://protofusion.org/hg/supermileage/raw-diff/271c53e52125/Arduino/Libraries/SoftwareSerial/SoftwareSerial.h
Can interrupt support be added to Sparkfun’s Pro Micro? I haven’t had much success trying to use your WInterrupts.c and pins_arduino.h files with the Pro Micro. It at first kept telling me the CORE_INTx_PIN were undefined which I think I had fixed by changing it to EXTERNAL_INT_x. Even still, it was acting intermittenly. Any thoughts?
links dont work, alas