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.

Setting Interrupt In Separate C File



Hi,

I have a code running with no problem. main, some other functions and ISRs were at the same "main.c" file and I decided to move some of the functions and ISRs into seperate files. Code is compiled successfully, there is no error/warnings. When I test the code using CCS/JTAG my initialized interrupts were working normally but code sometimes goes to DefaultISR.c-Spi or DefaultISR.c-Trip Zone Interrupt. In my code I dont use any spi or trip zone.When I only moved back ISRs to the main .c file, everything worked normal again. Other functions were at the different .c files at that time.

What I do when moving the ISRs from main.c is to create a "Interrupt.c" and "Interrupt.h". ISR functions are in the "Interrupt.c", and necessary headers are included.  "Interrupt.h" included in "Interrupt.c" and it contains function prototypes of ISR such as interrupt void ADC_ISR(void). Also in the header file of main.h, extern interrupt void ADC_ISR(void) is written. "main.h" is included in "main.c". All headers have include guard and there are no errors/warnings.

What could cause this error? Any idea?

- CPU F28377D, CCSv6.1.2, Compiler v6.4.9

Regards,

  • Hi,

    Its just some linking you're missing. What error do you observe?

    Regards,
    Gautam
  • Hi,
    Like I said, when I compile the project, I get no error/warnings. But when code running, code goes to spi or trip zone ISR randomly within the defaultISR.c file and hits ESTOP0, thus program halts. But when my ISR functions within the main.c file which includes main() and ISR functions, code runs perfectly.
  • Hello,

    I agree with Gautam here, it sounds like you are breaking some links when you move the ISR code to another file. Do you have some code like the following snippet?

    In Main.c:
    extern __interrupt void local_timer0_isr(); //located in custom_ints.c

    void main(){
    ...
    PieVectTable.TIMER0_INT = &local_timer0_isr;
    ...
    }

    In custom_ints.c:
    __interrupt void local_timer0_isr (){
    ...
    }

    Regards,
    Mark
  • I did like in below:

    In main.c;

    void main()
    {

    ...//Init Functions, InitSysCtrl, IPCBootCPU2 global variables init, peripheral inits...


    DINT;

    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();

    EALLOW;
    PieVectTable.EPWM7_INT = &ePWM_ISR;
    PieVectTable.ECAP1_INT = &eCAP1_ISR;
    EDIS;

    PieCtrlRegs.PIEIER4.bit.INTx1 = 1; //eCAP1
    PieCtrlRegs.PIEIER3.bit.INTx7 = 1; //ePWM7

    IER |= ( M_INT3 | M_INT4 ); //Enable eCAP1, ePWM7

    ....//Some other inits

    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM
    .
    .
    .
    //Background loop, state machines

    }

    In main.h;
    //extern function prototypes
    extern interrupt void ePWM_ISR(void);
    extern interrupt void eCAP1_ISR(void);

    In interrupts.c;
    #include ....//some include files associated with the ISRs
    #include " interrupts.h"
    interrupt void ePWM_ISR(void)
    {
    .
    .
    .
    //codes
    }

    interrupt void eCAP1_ISR(void)
    {
    .
    .
    .
    //codes
    }

    In interrupts.h;
    //Function protoype of ISRs
    interrupt void ePWM_ISR(void);
    interrupt void eCAP1_ISR(void);

    Could link order cause this? Project Properties ->Buid->Link Order, it is empty, I did not specify any linking order.