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 #194 background imageLoading...
Page #194 background image
Interrupts, The Big Picture
A real-world event might be our system responding to a push-button. Once again, the event could
be handled using either Polling or Interrupts.
It is common to see “simple” example code utilize Polling. As you can see from the left-side
example below, this can simply consist of a while{} loop that keeps repeating until a button-push
is detected. The big downfall here, though, is that the processor is constantly runningasking the
question, “Has the button been pushed, yet?”
Waiting for an Event: Button Push
100% CPU Load
while(1) {
// Polling GPIO button
while (GPIO_getInputPinValue()==1)
GPIO_toggleOutputOnPin();
}
// GPIO button interrupt
#pragma vector=PORT1_VECTOR
__interrupt void rx (void){
GPIO_toggleOutputOnPin();
}
> 0.1% CPU Load
Polling Interrupts
The example on the right shows an Interrupt based solution. Since this code is not constantly
running, as in the previous example’s while{} loop, the CPU load is very low.
Why do simple examples often ignore the use of interrupts? Because they are simple.
Interrupts, on the other hand, require an extra three items to get them running. We show two of
them in the right-hand example above.
The #pragma sets up the interrupt vector. The MSP430 has a handy pragma which makes it
easy to configure this item. (Note: we’ll cover the details of all these items later in this
chapter.)
The __interrupt keyword tells the compiler to code this function as an interrupt service routine
(ISR). Interrupt functions require a context save and restore of any resources used within
them.
While not shown above, we thought we’d mention the third item needed to get interrupts to work.
For a CPU to respond to an interrupt, you also need to enable the interrupt. (Oh, and you may
also have to setup the interrupt source; for example, we would have to configure our GPIO pin to
be used as an interrupt input.)
So, in this chapter we leave the simple and inefficient examples behind and move to the real-
world where real-world embedded systems thrive on interrupts.
5 - 4 MSP430 Workshop - Interrupts

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