1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Using Interrupts with WinAVR

Discussion in 'Embedded' started by Mak, Nov 16, 2005.

  1. Mak

    Mak Guest

    Hello all,

    This is an AVR specific problem. When I write a function for timer2
    overflow as follows:

    // Timer 2 overflow interrupt service routine
    interrupt(SIG_OVERFLOW2)//SIG_INTERRUPT0)//SIG_OVERFLOW2)
    {
    // Place your code here
    PORTD ^= _BV(7);
    }

    and make with winavr, I get the following warnings:

    E:/AVR/WinAVR/testfiles/isr.c:6: warning: return type defaults to `int'
    E:/AVR/WinAVR/testfiles/isr.c:6: warning: function declaration isn't a
    prototype
    E:/AVR/WinAVR/testfiles/isr.c: In function `interrupt':
    E:/AVR/WinAVR/testfiles/isr.c:6: warning: type of "__vector_4" defaults
    to "int"
    E:/AVR/WinAVR/testfiles/isr.c:9: warning: control reaches end of
    non-void function

    When I check the main.lss file, I notice that the interrupt routine is
    not correctly placed in the inetrrupt vector, and hence the code doesnt
    work,

    Can someone please tell me that is wrong here? Why cant I point the
    interrupt vector table towards my desired routine using this syntax and
    WinAVR?

    Thanks in advance

    Mak
     
    Mak, Nov 16, 2005
    #1
    1. Advertisements

  2. Mak

    Kurt Harders Guest

    Hallo,
    It should read
    INTERRUPT(SIG_OVERFLOW2)
    Yout defined a function interrupr returning an int.
    He is right. interrupt(xxx) is no prototype. But you did not want to
    write a prototype, you wanted the macro INTERRUPT
    You can, but you must use the correct spelling. All capital letters fpr
    this macro.

    Regards, Kurt
     
    Kurt Harders, Nov 16, 2005
    #2
    1. Advertisements

  3. Mak

    Tom Guest

    1 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: return type defaults to `int'
    2 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: function declaration isn't a
    3 > E:/AVR/WinAVR/testfiles/isr.c: In function `interrupt':
    4 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: type of "__vector_4" defaults
    5 > E:/AVR/WinAVR/testfiles/isr.c:9: warning: control reaches end of
    Looks to me like you need a return type on your function which in this case
    should be void. That should solve 1,2,3 and 5. I reckon 4 has something to
    do with your _BV() macro/function.

    As for positioning your code in the vector table I'm not sure but in the IAR
    compiler you need to use a pre-processor command __irq to tell the compiler
    to use a return from interrupt at the end of the ISR. It might instruct the
    linker where to put it as well but I'm not sure.
     
    Tom, Nov 16, 2005
    #3
  4. Mak

    Mak Guest

    Thanks for the input, I believe the capital letters solves the problem,
    I am at peace now :).

    Um... I may be defying the very basic laws of computer architecture,
    but can we design an interrupt which after completion, doesnt return to
    the place where its called from (i.e. continues from Program
    Counter+1), rather loads the PC with a completely different (for
    instance the beginning of a state machine (idle)) value?

    Thanks
     
    Mak, Nov 16, 2005
    #4
  5. Mak

    Tauno Voipio Guest

    What should be done with the baseline code state
    saved at the entry to the interrupt routine?

    You'll have to decide e.g. what to do with the
    call stack of te code that was interrupted.

    It is not difficult to fudge the return PC.
    It is difficult to do it so that nothing collapses.
     
    Tauno Voipio, Nov 16, 2005
    #5
  6. Mak

    Dave Hansen Guest

    Actually, in all likelihood it should read

    SIGNAL(SIG_OVERFLOW2)

    You almost never want to use INTERRUPT. Check the avr-libc docs.

    You also need to #include <avr/interrupt.h> and/or <avr/signal.h>
    somewhere.

    Regards,
    -=Dave
     
    Dave Hansen, Nov 16, 2005
    #6
  7. Mak

    Kurt Harders Guest

    Hi Dave,

    Thats true. I expected the OP to have a reason to use interrupt :).

    Regards, Kurt
     
    Kurt Harders, Nov 16, 2005
    #7
  8. Mak

    usenet Guest

    Um... I may be defying the very basic laws of computer architecture,
    You might want to look at the setjmp() and longjmp() functions
     
    usenet, Nov 16, 2005
    #8
  9. Mak

    Tauno Voipio Guest

    Please do not use longjump() in an interrupt service routine
    in an AVR - you'll end up with locked-up interrupt hardware.
     
    Tauno Voipio, Nov 16, 2005
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.