<< 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 current instruction completes.
  • The program counter as it is after the above instruction is pushed onto the stack. The stack is memory whose contents are kept in last in first out order. The stack pointer is always updated to point to the most recent element added to the stack. This allows the processor to call functions and track interrupts. When something is pushed onto the stack, the stack pointer is incremented and the pushed data is written to that location. When you copy out of the stack and decrement the stack pointer, this is called popping something off the stack.
  • The status register is pushed onto the stack.
  • The highest priority interrupt waiting to occur is selected.
  • Single source interrupts have their interrupt request flags reset automatically. Multiple source interrupt flags do not do this so that the interrupt service routine can determine what the precise cause was.
  • The status register with the exception of the SCG0 bit is cleared. This will bring the processor out of any low-power modes. This also disables interrupts (the GIE bit) during the interrupt.
  • The content of the interrupt vector is loaded into the program counter. Specifically the processor executes the instruction at the particular memory location (the interrupt vector) for that interrupt. This should always be a jump to the interrupt service routine.

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.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?

Ask