This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using Pragma Vectors outside of main.c

Other Parts Discussed in Thread: MSP430G2553

Hello
I have a quesiton. Can we use and define pragma vector's function outside of main (for example in header file or another c file). Can we define it in another c file or header file? For example i want to notify it in header file;

Here is my delay.h

#ifndef DELAY_H 
#define DELAY_H
extern void TimerDelay(unsigned int time);
extern unsigned char delayUs;
extern __interrupt void iis(void);     //compiler gives error for this line
#endif

And here is my delay.c

#include <msp430g2553.h>
#include "delay.h"


#pragma vector = TIMER1_A1_VECTOR
__interrupt void iis(void)
{
switch( TA1IV )
{
case 2: break;
case 4: delayUs--;break;
case 10: break;
}

}

After all, the compiler gives error. How should i define pragma vectors and its function in header file and that header's c file?

Kind regards... 

  • Snow said:
    How should i define pragma vectors and its function in header file

    Simply don't. Interrupt routine is not a function you call from your code, so why bother?

  • I'm try to creating a library and i want to collect all functions and interrupt routines relevant with it  . So we can only use and call interrupt routines from main.c, is it right?

  • You can define an ISR in any module you want. You don't (shouldn't) call ISRs from anywhere.

    It's not really necessary to declare an ISR in a header file.

    What error is the compiler giving?

  • Snow said:
    So we can only use and call interrupt routines from main.c, is it right?

    Wrong. ISR routines are called by interrupts, not by your code. Placement of ISR routine does not matter - you can put it in any module. There's no need to define ISR routing in header files.

  • How would you set that up? For example I have a main.c, aux.h, and aux.c files. aux.h is included in main.c and the ISR is defined in aux.c. It compiles with no errors however the ISR never gets called but if I copy and paste the ISR to the main.c file it works.

  • Two ways to do that.

    1. Add the file aux.c to the project.

    3. Include aux.c inside main.c

  • old_cow_yellow said:
    Include aux.c inside main.c

    Well, it is a common rule (even though violated sometimes even by people who should know better) that a .h file doesn't generate any code by its own and a .c file is a separate compilation unit.

    Option "3 of 2" is therefore only used by people who don't want everythign in one .c file (which is good) and are too lazy to write a proper .h file to be included into main.c (which is bad)

**Attention** This is a public forum