Electronic – Set up an ADC ISR, but every time an ADC Interrupt is called it goes to isr_trap.asm instead

adcinterruptsmsp430

I am trying to do a program with my MSP430FR6989 from Texas Instruments. I
send an Analogue signal to my ADC module in the uC, which converts it to a digital signal. If the value is greater than 0x800 (1.65 V), set a blue LED, else clear the blue LED

I am trying to do that with interrupts.

This is a snippet of my code

EDIT2 I added the whole code instead of the snippet

#include <msp430.h> 


#define ENABLE_PINS 0xFFFE

void ADC_SETUP (void);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    PM5CTL0 = ENABLE_PINS;
    P4DIR = BIT3;

    ADC_SETUP ();

    ADC12IER0 = ADC12IE0;

    _BIS_SR(GIE);

    ADC12CTL0 = ADC12CTL0 | ADC12ENC;
    ADC12CTL0 = ADC12CTL0 | ADC12SC;

    while(1);

    return 0;
}

void ADC_SETUP (void)
{
    #define ADC12_SHT_16      0x0200
    #define ADC12_ON          0x0010
    #define ADC12_SHT_SRC_SEL 0x0200
    #define ADC12_12BIT       0x0020
    #define ADC12_P92         0x000A

    ADC12CTL0 = ADC12_SHT_16 | ADC12_ON;
    ADC12CTL1 = ADC12_SHT_SRC_SEL;
    ADC12CTL2 = ADC12_12BIT;
    ADC12MCTL0 = ADC12_P92;
}


#pragma vector = ADC12_VECTOR//0xFFEA//ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
    if(ADC12MEM0 > 0x0800)
        P4OUT = BIT3;
    else
        P4OUT = 0x00;

    ADC12CTL0 = ADC12CTL0 | ADC12SC;
}

when I build it, I get this warning.

#2580-D pragma vector = accepts numeric arguments or
"unused_interrupt" but not ADC12_VECTOR

When I debug it, and my uC goes to Line A and the ADC12SC bit is set, it goes to isr_trap.asm, and my uC is stuck there

Kindly help me with this issue.

Start of EDIT_0

MSP430FR6989

Code Composer Studio 6.1.0

Compiler: TI v4.4.3

End of EDIT_0

Start of EDIT_1

I can't copy and paste the .map file here as it is too big, as I exceeded the character limit for this post.

Instead, I copied the file into a text file and sent it to this link.

https://we.tl/t-4aECqSr4yA

It is called ADC_ISR_UDEMY.map.txt

End of EDIT_1

Start of EDIT_3

Sorry for the late reply, I appreciate everyone's help in this thread.

I tried doing 3 projects, one with Timer A0 CCR0 ISR (ISR_TRAP_TIMER_TEST), one with ADC12_B ISR (ISR_TRAP_ADC_TEST), and one with ADC12_B isr with @GVelascoh Header (ISR_TRAP_ADC_HEADER_2).

ISR_TRAP_TIMER_TEST
worked fine, the P1.0 LED was blinking

#include <msp430.h> 

#define ENABLE_PINS 0xFFFE

void init_Timer (void);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    PM5CTL0 = ENABLE_PINS;
    P1DIR = BIT0;

    init_Timer ();

    _BIS_SR(GIE);

    while(1);

    return 0;
}

void init_Timer (void)
{
    TA0CTL = TASSEL__ACLK | MC__UP;
    TA0CCR0 = 3000;
    TA0CCTL0 = CCIE;
}

#pragma vector = TIMER0_A0_VECTOR //TA0 CCR0
__interrupt void Test_ISR (void)
{
    P1OUT = P1OUT ^ BIT0;

    //clear the flag
}

Build:

**** Build of configuration Debug for project ISR_TRAP_TIMER_TEST ****

"C:\\ti\\ccsv6\\utils\\bin\\gmake" -k all 
'Building file: ../main.c'
'Invoking: MSP430 Compiler'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --include_path="C:/ti/ccsv6/ccs_base/msp430/include" --include_path="C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
"../main.c", line 19: warning #112-D: statement is unreachable
"../main.c", line 17: remark #1527-D: (ULP 2.1) Detected SW delay loop using empty loop. Recommend using a timer module instead
'Finished building: ../main.c'
' '
'Building target: ISR_TRAP_TIMER_TEST.out'
'Invoking: MSP430 Linker'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal -z -m"ISR_TRAP_TIMER_TEST.map" --heap_size=160 --stack_size=160 --cinit_hold_wdt=on -i"C:/ti/ccsv6/ccs_base/msp430/include" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/lib" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" -i"C:/ti/ccsv6/ccs_base/msp430/lib/5xx_6xx_FRxx" -i"C:/ti/ccsv6/ccs_base/msp430/lib/FR59xx" --reread_libs --priority --warn_sections --display_error_number --diag_wrap=off --xml_link_info="ISR_TRAP_TIMER_TEST_linkInfo.xml" --use_hw_mpy=F5 --rom_model -o "ISR_TRAP_TIMER_TEST.out" "./main.obj" "../lnk_msp430fr6989.cmd"  -l"libmath.a" -l"libc.a" 
<Linking>
remark #10372-D: (ULP 4.1) Detected uninitialized Port A in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port B in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port C in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port D in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port E in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
'Finished building target: ISR_TRAP_TIMER_TEST.out'
' '

**** Build Finished ****

ISR_TRAP_ADC_TEST
The uC still goes to the isr_trap.asm

#include <msp430.h> 

#define ENABLE_PINS 0xFFFE

void init_ADC (void);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    PM5CTL0 = ENABLE_PINS;
    P1DIR = BIT0;

    init_ADC ();

    _BIS_SR(GIE);

    ADC12CTL0 = ADC12CTL0 | ADC12ENC;
    ADC12CTL0 = ADC12CTL0 | ADC12SC;

    while(1);

    return 0;
}

void init_ADC (void)
{
    ADC12CTL0 = ADC12ON | ADC12SHT0_2;
    ADC12CTL1 = ADC12SHP;
    ADC12CTL2 = ADC12RES__12BIT;
    ADC12MCTL0 = ADC12INCH_10;

    ADC12IER0 = ADC12IE0;
}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
    if(ADC12MEM0 > 0x0800)
        P1OUT = BIT0;
    else
        P1OUT = 0x00;
}

Build:

**** Build of configuration Debug for project ISR_TRAP_ADC_TEST ****

"C:\\ti\\ccsv6\\utils\\bin\\gmake" -k all 
'Building file: ../main.c'
'Invoking: MSP430 Compiler'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --include_path="C:/ti/ccsv6/ccs_base/msp430/include" --include_path="C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
"../main.c", line 22: warning #112-D: statement is unreachable
"../main.c", line 20: remark #1527-D: (ULP 2.1) Detected SW delay loop using empty loop. Recommend using a timer module instead
"../main.c", line 35: warning #2580-D: pragma vector= accepts numeric arguments or "unused_interrupts" but not ADC12_VECTOR
'Finished building: ../main.c'
' '
'Building target: ISR_TRAP_ADC_TEST.out'
'Invoking: MSP430 Linker'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal -z -m"ISR_TRAP_ADC_TEST.map" --heap_size=160 --stack_size=160 --cinit_hold_wdt=on -i"C:/ti/ccsv6/ccs_base/msp430/include" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/lib" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" -i"C:/ti/ccsv6/ccs_base/msp430/lib/5xx_6xx_FRxx" -i"C:/ti/ccsv6/ccs_base/msp430/lib/FR59xx" --reread_libs --priority --warn_sections --display_error_number --diag_wrap=off --xml_link_info="ISR_TRAP_ADC_TEST_linkInfo.xml" --use_hw_mpy=F5 --rom_model -o "ISR_TRAP_ADC_TEST.out" "./main.obj" "../lnk_msp430fr6989.cmd"  -l"libmath.a" -l"libc.a" 
<Linking>
remark #10372-D: (ULP 4.1) Detected uninitialized Port A in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port B in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port C in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port D in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port E in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
'Finished building target: ISR_TRAP_ADC_TEST.out'
' '

**** Build Finished ****

ISR_TRAP_ADC_HEADER_2
I still got the same issue, where the uC goes to isr_trap.asm (I hope I added your header right @GVelascoh)

#include <msp430.h> 


#define ENABLE_PINS 0xFFFE

void init_ADC (void);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    PM5CTL0 = ENABLE_PINS;
    P1DIR = BIT0;

    init_ADC ();

    _BIS_SR(GIE);

    ADC12CTL0 = ADC12CTL0 | ADC12ENC;
    ADC12CTL0 = ADC12CTL0 | ADC12SC;

    while(1);

    return 0;
}

void init_ADC (void)
{
    ADC12CTL0 = ADC12ON | ADC12SHT0_2;
    ADC12CTL1 = ADC12SHP;
    ADC12CTL2 = ADC12RES__12BIT;
    ADC12MCTL0 = ADC12INCH_10;

    ADC12IER0 = ADC12IE0;
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
    if(ADC12MEM0 > 0x0800)
        P1OUT = BIT0;
    else
        P1OUT = 0x00;
}
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif

Build:

**** Build of configuration Debug for project ISR_TRAP_ADC_HEADER_2 ****

"C:\\ti\\ccsv6\\utils\\bin\\gmake" -k all 
'Building file: ../main.c'
'Invoking: MSP430 Compiler'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --include_path="C:/ti/ccsv6/ccs_base/msp430/include" --include_path="C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
"../main.c", line 23: warning #112-D: statement is unreachable
"../main.c", line 21: remark #1527-D: (ULP 2.1) Detected SW delay loop using empty loop. Recommend using a timer module instead
"../main.c", line 37: warning #2580-D: pragma vector= accepts numeric arguments or "unused_interrupts" but not ADC12_VECTOR
'Finished building: ../main.c'
' '
'Building target: ISR_TRAP_ADC_HEADER_2.out'
'Invoking: MSP430 Linker'
"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/bin/cl430" -vmspx --abi=eabi --data_model=restricted --use_hw_mpy=F5 --advice:power=all --advice:hw_config=all -g --define=__MSP430FR6989__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal -z -m"ISR_TRAP_ADC_HEADER_2.map" --heap_size=160 --stack_size=160 --cinit_hold_wdt=on -i"C:/ti/ccsv6/ccs_base/msp430/include" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/lib" -i"C:/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.3/include" -i"C:/ti/ccsv6/ccs_base/msp430/lib/5xx_6xx_FRxx" -i"C:/ti/ccsv6/ccs_base/msp430/lib/FR59xx" --reread_libs --priority --warn_sections --display_error_number --diag_wrap=off --xml_link_info="ISR_TRAP_ADC_HEADER_2_linkInfo.xml" --use_hw_mpy=F5 --rom_model -o "ISR_TRAP_ADC_HEADER_2.out" "./main.obj" "../lnk_msp430fr6989.cmd"  -l"libmath.a" -l"libc.a" 
<Linking>
remark #10372-D: (ULP 4.1) Detected uninitialized Port A in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port B in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port C in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port D in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port E in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
'Finished building target: ISR_TRAP_ADC_HEADER_2.out'
' '

**** Build Finished ****

End of EDIT_3

Start of EDIT_4

Thank you for your help, I fixed my problem, I uninstalled CCS v6.1.0 and installed CCS 8.2.0, written the same program, and the problem is gone.

Thought I would share this, so I won't leave it hanging.

End of EDIT_4

Best Answer

From your map file, it seems like your ISR function is not compiled as there is no code associated with it. In the "section allocation map" you can find that there is no reference to the symbol ADC12_ISR

.text:_isr 
*          0    00004400    00000020     
                00004400    0000001a     rts430x_lc_rd_eabi.lib : boot_special.obj (.text:_isr:_c_int00_noargs_noexit)
                0000441a    00000006                            : isr_trap.obj (.text:_isr:__TI_ISR_TRAP)

This is a part of a map file for another project I have, see how ISR symbols are detailed in it:

.text      0    0000c600    00000d30     
                0000c600    0000023c     main.obj (.text:main)
                   ...
                0000cc62    0000007e     my-lib-Debug_2.lib : events.obj (.text:events_insert)
                0000cce0    0000007c                            : i2c_master.obj (.text:_isr:USCIB0_ISR)
                0000ce30    0000005e     port_interrupts.obj (.text:_isr:Port3_ISR)
                   ...

Try cleaning your project and rebuild it again. Also, which files are you including, as the code you posted is not compilable as it is. Also, from the map file, I see you have another function, ADC_SETUP.

Edit: I just see that in your code you are not turning off the watchdog, which is enabled at start. Usually, this line is added at the beginning of the main function to do so: WDTCTL = WDTPW | WDTHOLD;


If your problem is due to compiler, this preprocessor conditionals will help you:

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif