Lab 8
Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 29
Lab 8d – Using Interrupts
Interrupts are a key part of embedded systems. It is responding to external events and
peripherals that allow our programs to ‘talk’ to the real world.
Thusfar, we have actually worked with a couple different interrupts without having to know
anything about them. Our serial communications involved interrupts, although the Wiring
language insulates us from needing to know the details. Also, there is a timer involved in the
delay() function; thankfully, it is also managed automatically for us.
In this part of the lab exercise, you will setup two different interrupts. The first one will be triggered
by the pushbutton; the second, by one of the MSP430 timers.
1. Once again, let’s start with the Blink code.
File Examples 1.Basics Blink
2. Save the sketch to a new file.
File Save As…
Save it to:
C:\msp430_workshop\<target>\energia\Interrupt_PushButton
3. Before we modify the file, run the sketch to make sure it works properly.
4. To setup(), configure the GREEN_LED and then initialize it to LOW.
This requires two lines of code which we have used many times already.
Adding an Interrupt
Adding an interrupt to our Energia sketch requires 3 things:
An interrupt source – what will trigger our interrupt. (We will use the pushbutton.)
An ISR (interrupt service routine) – what to do when the interrupt is triggered.
The interruptAttach() function – this function hooks a trigger to an ISR. In our case, we
will tell Energia to run our ISR when the button is pushed.
5. Interrupt Step 1 - Configure the PushButton for input.
Look back to an earlier lab if you don’t remember how to do this.
6. Interrupt Step 2 – Create an ISR.
Add the following function to your sketch; it will be your interrupt service routine. This is about
as simple as we could make it.
void myISR()
{
digitalWrite(GREEN_LED, HIGH);
}
In our function, all we are going to do is light the GREEN_LED. If you push the button and the
Green LED turns on, you will know that successfully reached the ISR.