NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » can a function be used in an isr?

February 03, 2011
by cujofever
cujofever's Avatar

I managed to get a pin interrupt to work but would like to take it a step further. My project is using code from the tempsensor project provided with the nerdkit. In the isr I tried calling the adc_read function but it didn't work. Is it possible to call functions from within the isr brackets? I am trying to capture an accelerometer value when a button is pressed. I would like to press the button, delay a second, grab an adc measurement, then return to my while loop. The delay is so that the user is not touching the device/button while avr is capturing the accel. value. Thanks

February 03, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi cujofever,

The short answer is yes, you can definitely call a function from inside an ISR and it should work as expected, however there are a few reasons why it is not very common to do this. While an interrupt is running, it blocks all other interrupts from firing so usually you want to get out of the interrupts as fast as possible. When you make a call to a separate function it takes time to save all the registers and make the jump to the called function. Calling a function from an interrupt handler is possible though, and there is probably something subtle in your code that is causing it not to work.


Post a Reply

Please log in to post a reply.

Did you know that you can connect a computer keyboard to your microcontroller? Learn more...