[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] newbie interrupts question

From: Ned Konz
Subject: Re: [avr-gcc-list] newbie interrupts question
Date: Mon, 8 May 2006 18:16:05 -0700

Eric Smith wrote:

Now I'd like to improve the timing in this code by using the RTC timer with inerrupts. I read an example of how to set up the interrupt vectors at the beginning of memory using assembly - each vector has a relative jump to the appropriate routine. My question is this: how do I set up this interrupt vector table using C? Or, if I have to mix assembly with C to do it, that's fine -- but can you tell me (show me) explicitely how to do it? I have to be able to set up the interrupt vectors such that when my timer reaches zero, and the interrupt is generated, the appropriate routine is called. Also, I'm assuming that if I enable interrupts I'll need vectors for all available interrupts even if I'm only going to use one, is that right?

You don't have to explicitly define interrupt handlers for unused interrupts. What happens is this:

* When you use ISR() with the (macro) name of an interrupt (see <avr/ interrupt.h> and <avr/iom8.h>) it expands to a name like "__vector_18" (I don't have the headers in front of me; the name could be slightly different).

* There (are in the library) definitions for each of the interrupts in your processor; each of them jump to a function that you can override that's called _bad_interrupt(). But each of these definitions is marked "weak" so that if you define one yourself, your definition will override the library one.

The result of this is that all you have to do is to define (using ISR ()) handlers for the interrupts of interest in your program. The rest will be taken care of automatically. So the result looks something like this (double-check the names of course):

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

// global interrupt flag is off here
// start another ADC conversion

int main(void)
        // initialize ADC, timer, etc.
        set_sleep_mode(SLEEP_MODE_ADC); // or whichever one you need
        sei();  // enable global interrupts
        // main loop: do nothing but sleep
        for (;;)


Ned Konz
MetaMagix embedded consulting

reply via email to

[Prev in Thread] Current Thread [Next in Thread]