Project

General

Profile

MSP430 Interrupts

The MSP430 relies on interrupts to reduce CPU load to the point where it can be disabled to save power. All peripheral modules have the ability to request an interrupt, for example, when the UART receives a new character.

First, enable global interrupts once setup of the peripherals is complete:
__bis_SR_register(GIE);

To disable global interrupts:
__bic_SR_register(GIE);

Every interrupt has an Interrupt Enable bit and an Interrupt Flag bit. For example, the USCI module in UART mode has the UCA0TXIE bit in the IE2 register, and the UCA0TXIFG bit in the IFG2 register. To enable the USCI_A0_TX interrupt, set the UCA0TXIE bit. When the USCI module requests the USCI_A0_TX interrupt, the CPU will execute the code in the USCIAB0TX ISR:
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void){
if(IFG2 & UCA0TXIFG){
UCA0TXBUF = foo;
//Do stuff
}
}
The #pragma vector and __interrupt identify the USCIAB0TX_ISR(void) function as the Interrupt Service Routine (ISR) to execute when the USCIAB0TX interrupt is requested. The ISR is often required to clear the associated interrupt flag, however, this is often done automatically by reading or writing a related register. In this case, the UCA0TXIFG interrupt flag is cleared by writing to UCA0TXBUF.

Note also that the interrupt vector is USCIAB0TX_VECTOR, not USCIA0TX_VECTOR. On the MSP430G2553, the interrupt vector is shared by both parts of the USCI module, so the interrupt request may occur at times other than when the UART Tx buffer is empty. So, check if the UCA0TXIFG flag is set before executing the ISR code.

Finding the interrupt vector name can be tricky, as interrupts are often shared or have different name from the control bits. Neither the device specific data sheet or the user guide contain the interrupt names. However, you can find the interrupt vector name in the device specific header file.
The above code is for the MSP430G2553. It has