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.

Noob ISR C Code Question

Other Parts Discussed in Thread: MSP430WARE

Hi Guys,

I searched the Forum but came up blank....

Generic assembly code ISR handler:

;***
; Int Handler for Timer B0 Modules 1 Thru 6
;***
TIMER0_B1
    add &TB0IV,PC     ;Add Offset To Jump Table

    RETI     ;Just In Case
    jmp TIMB0_1     ;Module 1 ;Vector
    jmp TIMB0_2     ;Module 2 ;Vector
    jmp TIMB0_3     ;Module 3 ;Vector
    jmp TIMB0_4     ;Module 4 ;Vector
    jmp TIMB0_5     ;Module 5 ;Vector
    jmp TIMB0_6     ;Module 6 ;Vector


TBOF

    Do Something
    RETI     ;Timer A OverFlow

TIMB0_3 

 Do Something  

  RETI

How can I handle (write the code) the ISR in C?

Thanks!

Charlie

  • Depends on which toolchain you use. The IAR documentation explains how to do this for that tool.

    Here's an example from MSP430Ware (examples/driverlib/MSP430F5xx_6xx/usci_a_uart/usci_a_uart_ex1_rx.c)

    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR (void)
    {
        switch (__even_in_range(UCA0IV,4)){
            //Vector 2 - RXIFG
            case 2:
    
                //USCI_A0 TX buffer ready?
                while (!USCI_A_UART_getInterruptStatus(USCI_A0_BASE,
                           USCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) ;
    
                //Receive the data
                receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
    
                //Echo received data
                USCI_A_UART_transmitData(USCI_A0_BASE,
                receivedData);
    
                break;
            default: break;
        }
    }
    

  • There's a better example for you in the MSP430Ware library:

    examples/driverlib/MPS430F5xx_6xx/timer_b/timer_b_ex1_continuousModeCCR0.c

    Also, reference this post on how the peripherals and corresponding vectors are named.

  • Thanks Brian!

    I didn't think to check the MSP430WARE library!

    I am in the process of translating my old assembly code to C so this is a big help.

    Thanks again!

    Charlie

  • Actually, the __even_in_range intrinsic was introduced to do exactly this: replace the if-chain of a normal switch by a jumptable like the one in the assembly code. For a jumptable, the compiler needs to know that the source is an even value from 0 to x. Which you tell him with this intrinsic.

**Attention** This is a public forum