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.

How to use the MSP430 interrupt in other C files

Other Parts Discussed in Thread: MSP430F5438A

The interrupt function used in other C files, rather than the use of main.c interrupt. Can be achieved? The use of methods and main.c like? Examples are the best.

please help!

best   wish!

  • There is nothing special about interrupt functions that would prevent you from moving them to other files. What exactly is the problem?
  • These two days to write a program, since the relevant code TA longer, directly write a timer.c put the code related functions, including the interrupt service routine. It was found that the program can be compiled to download, but it does not work interrupt function. Later this function where you can run into main.c correct.
    I remember extern interrupt function is not declared on the outside that the interrupt function main.c how to use it?

    PS:  IAR 5.3     MSP430F5438A

  • Interrupt service routines can be defined in source files other than the one containing main() -- I do it all the time. The "#pragma vector=" constructs the linkage. (__interrupt deals with how the ISR is compiled.)

    There is one (unusual) thing to watch out for: The linker will not resolve an ISR from a library, since there is no code which references the name. This is not incorrect, but it's often surprising. If this is what you're trying to do, the simplest thing is just to not put it into a library.

    What symptom are you seeing? If the ISR code were not being linked into your program, the symptom would be a reset when the interrupt is triggered. If that's not what you're seeing, maybe the problem is elsewhere.

  • Just a small correction: It' snot because 'there is no code which references the name'. If the library code contained the #pragma, then there is 'code' that rerferences the ISR. However, the linker has no reason to include this code/the reference from a library. Library code is only included if it is referenced from a project file. Anything that is not referenced by code that was already included, will be ignored, including the reference generated by the #pragma.

    So in general, an ISR should be placed into the same source file as the code that enables its use. If this code is included, it also means that any global variable or reference in the same source file will be included too and therefore the ISR will be included, no matter whether it is in a library.
    If the code that enables the interrupts is not used by the project, then there is no need for including the ISR. :)

**Attention** This is a public forum