EasyManuals Logo

Texas Instruments MSP430 Student Guide

Texas Instruments MSP430
398 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #215 background imageLoading...
Page #215 background image
Coding Interrupts
ISR Example for Grouped Interrupts
The code for a grouped ISR begins similar to any MPS430 interrupt service routine; you should
use the #pragma vector and __interrupt keyword syntax.
#pragma vector=PORT1_VECTOR
__interrupt void myISR(void) {
switch(__even_in_range( P1IV, 10 )) {
case 0x00: break; // None
case 0x02: break; // Pin 0
case 0x04: break; // Pin 1
case 0x06:
GPIO_toggleOutputOnPin
(…); // Pin 2
break;
case 0x08: break; // Pin 3
case 0x0A: break; // Pin 4
case 0x0C: break; // Pin 5
case 0x0E: break; // Pin 6
case 0x10: break; // Pin 7
default: _never_executed();
}}
Interrupt Service Routine (Group INT)
INT Source
IV Register
Vector Address
Loc’n
GPIO (Port 1) P1IV
PORT1_VECTOR
47
#pragma vector assigns
myISR’ to correct location
in vector table
__interrupt keyword tells
compiler to save/restore
context and RETI
Reading P1IV register:
Returns value for
highest priority INT
for the Port 1 ‘group’
Clears IFG bit
Tell compiler to ignore
un-needed switch cases
by using intrinsics:
__even_in_range()
_never_executed()
For grouped interrupts, though, we also need to determine which specific source caused the CPU
to be interrupted. As we’ve described, the Interrupt Vector (IV) register is an easy way to
determine the highest-priority, pending interrupt source. In the case of GPIO port 1, we would
read the P1IV register.
It’s common to see the IV register read within the context of a switch statement. In the above
case, if the P1IV register returns “6”, it means that pin 2 was our highest-priority, enabled
interrupt on Port 1; therefore, its case statement is executed. (Note, the return values for each IV
register are detailed in the F5xx device Users Guide and the F5xx DriverLib User’s Guide. You
will find similar documentation for all MSP430 devices..)
If our program was using Pin 2 on Port 1, you should see the code for case 0x06 executed if the
GPIO interrupt occurs.
By the way, there are two items in the above code example which help the compiler to produce
better, more optimized, code. While these intrinsic functions are not specific to interrupt
processing, they are useful in creating optimized ISRs.
The __even_in_range() intrinsic function provides the compiler a bounded range to evaluate.
In other words, this function tells the compiler to only worry about even results that are lower
or equal to 10.
Likewise the _never_executed() intrinsic tells the compiler that, in this case, “default” will
never occur.
MSP430 Workshop - Interrupts 5 - 25

Table of Contents

Other manuals for Texas Instruments MSP430

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments MSP430 and is the answer not in the manual?

Texas Instruments MSP430 Specifications

General IconGeneral
BrandTexas Instruments
ModelMSP430
CategoryMicrocontrollers
LanguageEnglish

Related product manuals