<< Chapter < Page | Chapter >> Page > |
When the interrupt first occurs on the MSP there is a precise order of events that will occur. This process takes 6 instruction cycles to occur.
The interrupt service routine is the code that the programmer writes to take care of the work that needs to be done when a particular interrupt happens. This can be anything you need it to be. Because entering the interrupt turned off the GIE bit, you will not receive any interrupts that happen while you are still in the interrupt service routine. You can turn the interrupts back on if you need to receive interrupts during your interrupt, but usually it is a better idea to make interrupt service routines shorter instead. In C interrupts are simply functions with special declarations. You never call these functions; the compiler simply sets up the interrupt vector table to call your function when the particular interrupt occurs.
This example interrupt is pulled from the fet140_wdt01.c example file by Mark Buccini. The complete file is in the Rowley directory under samples/msp430p140_C.
// Watchdog Timer interrupt service routine
void watchdog_timer(void) __interrupt[WDT_VECTOR]
{
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
Interrupt functions should always be void and accept no arguments. This particular interrupt service routine (ISR) is called watchdog_timer, but the name does not matter. The way the compiler knows that this function should handle the watchdog timer interrupt is what follows the function name. The __interrupt[] indicates that this is an interrupt and WDT_TIMER is a macro from the MSP header file. Every interrupt vector in the processor has a macro defined for it. To attach this interrupt service routine to a different interrupt, all you need to do is change the WDT_TIMER to one of the other macros defined in the header msp430x16x.h.
Notification Switch
Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?