Automate 69 Posted January 7, 2014 Share Posted January 7, 2014 The documentation for the attachInterrupt function states: Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. What about micros(), does it work? I can understand these limitations for the lower end MSP430s but what about the 5529, Tiva-C and C2000? Do they have the same limitations? Any chance the interrupt handling could be enhanced on the higher end MCUs? Also, any chance at timer interrupts in Energia or will that always need to be done something like this http://forum.stellarisiti.com/topic/1754-interrupt-handler-in-energia/ Thanks, Quote Link to post Share on other sites
roadrunner84 466 Posted January 7, 2014 Share Posted January 7, 2014 micros()/millis() do work, because you're just getting some data. But be sure not to "block" the flow during an interrupt. In particular, this code does not work and in addition is very bad design void functionToBeAttached() { int start = micros(); // some code while(micros() - start < 20); // wait 20 microseconds // some other code } micros()/millis() do give you information, but they do not get updated while you're in your function. This kind of coding can (though will not always when using micros()) thus result in an infinite loop. If you do need to wait for a set time, instead use the flag polling strategy: bool buttonPressed = false; void loop() { if (buttonPressed) { // some code delay(20); buttonPressed = false; // some other code } } void funcionToBeAttached() { buttonPressed = true; } This behaviour is resulting from the way Energia keeps track of millis(), which is also on an interrupt. All of the named controllers have just one CPU, and thus can handle only one interrupt simultaneously. Quote Link to post Share on other sites
bblincoe 1 Posted January 7, 2014 Share Posted January 7, 2014 It is important to remember that interrupt routines should be kept as simple (and short) as possible. When they are being executed no other code is running and (typically) interrupts are disabled. If you're blocking on one interrupt (say a push button) you may lose data coming in over UART! Note: The handler is simply a callback function that is called from the interrupt routine defined at the interrupt vector. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.