Monthly Archives: September 2011

Interrupting msp430!!!

The key feature of msp is the lower power mode which requires us to know how to put it to sleep and wake it. This is one main reason why we should and must know interrupts in msp.The interrupts can be classified into three types as:

  • System Reset
  • Maskable NMI
  • Non maskable NMI

The system Reset is of types

  • Power up clear (PUC)
  • Power on Reset (POR)

POR is associated with powering up of the device and a reset signal on RST/NMI pin. PUC is triggered by a POR and also watchdog timer and security violation (unauthorised memory access by programs).

Maskable interrupts are caused by peripherals and are enabled or disabled by the GIE(global interrupt enable) bit in Status register.The different maskable interrupts are

  • External interrupts
  • Timer Interrupts
  • Serial
  • ADC …etc.

The Non maskable interrupt refers to an interrupt which when enabled is not disabled by the GIE bit (global interrupt enable) in Status register.There are basically three different NMI’s.

  1. an edge on RST/NMI pin
  2. oscillator fault
  3. memory access violation

Each interrupt is associated with a corresponding Interrupt service routine which is located in a different location based on the interrupt.In C programming we define the ISR by using the directive #pragma and using keyword vector.The executed interrupt depends on the value of the vector.For example if we need to use the interrupts for the PORT1 pins then the vector should be declared as

#pragma vector=PORT1_VECTOR
__interrupt void isr(void)

The different vector s can be found in the header file.They are

 * Interrupt Vectors (offset from 0xFFE0)
 #define PORT1_VECTOR                (2 * 2u)  /* 0xFFE4 Port 1 */
 #define PORT2_VECTOR               (3 * 2u)  /* 0xFFE6 Port 2 */
 #define USI_VECTOR                     (4 * 2u)  /* 0xFFE8 USI */
 #define ADC10_VECTOR               (5 * 2u)  /* 0xFFEA ADC10 */
 #define TIMERA1_VECTOR          (8 * 2u)  /* 0xFFF0 Timer A CC1, TA */
 #define TIMERA0_VECTOR         (9 * 2u)  /* 0xFFF2 Timer A CC0 */
 #define WDT_VECTOR                  (10 * 2u) /* 0xFFF4 Watchdog Timer */
 #define NMI_VECTOR                   (14 * 2u) /* 0xFFFC Non-maskable */
 #define RESET_VECTOR              (15 * 2u) /* 0xFFFE Reset [Highest Priority] */

By replacing the value of the vector the function will serve as the ISR for that particular interrupt.If PORT1_VECTOR is replaced with NMI_VECTOR then the ISR will run on the ocurence of NMI and not PIN interrupt.

All the maskable interrupts have to be enabled first before they can be used.To use the interrupts first we have to set the global interrupt enable bit in SR.This can be done by using the intrinsic function

__EINT();     if this function is not used then even if we enable individual interrupts they wont function.

External Interrupts On GPIO

Each port is associated with PxIE , PxIES , PxIFG registers which are used to control the interrupts.The interrupt on a particular pin is enabled by setting the particular bit in PxIE.ex:

P1IE=BIT3;             //enebles interrupt on pin 3

The PxIES is used to select if we need rising edge or the falling edge of the signal to trigger the interrupt.setting a bit makes the interrupt on that pin to be triggered on a rising edge and resetting makes it a falling edge triggered.

0= rising edge

1= falling edge

When an interrupt is triggered on a pin, the bit corresponding to that pin is set.These bits have to be manually reset once the ISR has been served.

Given below is  a code which uses a port pin as an interrupt to toggle the led.


P1DIR=BIT0+BIT6;              // MAKE PIN 0 AND PIN 3 AS OUTPUTS.
P1OUT=BIT0;                   //MAKE PIN 0 HIGH
P1IE=BIT3;                    //ENABLE THE INTERRUPT FOR THE PIN 3


#pragma vector=PORT1_VECTOR     //ISR FOR PORT1
__interrupt void P1(void)
P1OUT^= (BIT0+BIT6);            //TOGGLE


Timer Interrupt

I’ll explain the controlling of a timer later but at the moment we should know that by giving the vector value as TIMERA1_VECTOR the ISR will function on an interrupt when timer overflows.

NMI Interrupt on RST/NMI

To use RST/NMI as an interrupt pin we have to set two bits.One in WDTCTL register and one in IE1 register.The oscillator fault is triggered when there is an error in the oscillator.It is used to switch toDCO when the crystal oscillator is not present.

By modifying the WDTNMIES bit in WDTCTL we can change the triggering edge of the NMI.

The following code initializes the pin and toggles the led on interrupt.

  IE1=NMIIE;                    //enable nmi
  WDTCTL=WDTPW+WDTHOLD+WDTNMI;  //select nmi function on RST/NMI

#pragma vector=NMI_VECTOR
__interrupt void nmi(void)
 P1OUT^= (BIT0+BIT6);

 IFG1&=~NMIIFG;                      //clear nmi interrupt flag
 IE1=NMIIE;                          // enable nmi
 WDTCTL = WDTPW + WDTHOLD+WDTNMI;    // select nmi function on RST/NMI


Its weird that in the above code interchanging the last 2 lines in ISR will not set the RST/NMI pin nmi mode.
1 Comment

Posted by on September 12, 2011 in Flip, MSP430 Tutorials


Tags: , ,

booster pack

Hey guys,

today I got my shipment of 430BOOSTER PACK for msp430 launch pad.Costed me around 800 to get it.Thanks to Kunal who helped me with the transaction.I immediately unpacked it.It really feels bad to tear the neatly packed cover the e14 guys mail it in.I didnt have a soldering iron at that time so i got to another friends house to get it done and finally connected the launch pad to the booster pack and tada!!! the booster pack came to life… I tried the media pad software and also a simulation of the pad itself.I think after telling all my friends about it i was satisfied and now m going through the really amazing how much can be done in so less.I want to try out the other touchpads that are available here.If any of you have already done it then please share the link.So i ll get back to my new love.Hope i can do a lot more new stuff and experiments!!!

1 Comment

Posted by on September 7, 2011 in Flip