Fun with interrupts on MSP-EXP430FR5739 FRAM Experimenter Board

Print Friendly, PDF & Email

Just a small program coded for learning interrupts. Code is commented and self explanatory.

Hardware :TI MSP-EXP430FR5739 FRAM Experimenter Board

Target Board

Software : Code Composer Studio Version: 4.2.3.00004

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Blink LEDs using button S1 and S2 and interrupts.
 * In MSP-EXP430FR5739 FRAM board there are 8 user programmable LEDs
 * four of them are connected to PORTJ pins 0..3 and
 * another four are to PORT3 4..7 pins.
 * LEDs are connected to GND via current limiting resistors.
 * Button S1 and S2 are connected to GND via PORT4 0&1 respectively
 * --coded by Ishan Karve (ishan.karve@gmail.com), Feb 12 as part of his self learning process
 */


#include <msp430fr5739.h>

//defines for MSP-430FR5739 EXP Board
#define S1      BIT0 //P4.0
#define S2      BIT1 //P4.1
#define LED0    BIT0 //PJ.0
#define LED1    BIT1 //PJ.1
#define LED2    BIT2 //PJ.2
#define LED3    BIT3 //PJ.3
#define LED4    BIT4 //P3.4
#define LED5    BIT5 //P3.5
#define LED6    BIT6 //P3.6
#define LED7    BIT7 //P3.7
//define for quarature encoder
#define CH_A    BIT
#define CH_B    BIT
#define BUTTON  BIT
#define COMM    BIT

void main(){
    //stop watchdog
    WDTCTL = WDTPW + WDTHOLD;
    //Select pins 4,5,6,7 of Port 3 and 0 to 3 of Port J for output
    PJDIR|=(LED0+LED1+LED2+LED3);
    P3DIR|=(LED4+LED5+LED6+LED7);
    //turn off leds on both P3 and PJ
    PJOUT&=~(LED0+LED1+LED2+LED3);
    P3OUT&=~(LED4+LED5+LED6+LED7);
    //setup interrupts for buttons S1 and S2
    P4DIR=0x00; //all ports as inputs
    P4IE|=(S1+S2);  //enable interrupts for S1 button
    //Button S1 and S2 are in active-low configuration
    P4REN=(S1+S2);//enable pullups on resoective ports
    //Since S1,S2 are in an active low config,
    //the other end of the resistor has to be pulled high
    P4OUT=(S1+S2);
    P4IFG&=~(S1+S2); //clear interrupt flag
    _enable_interrupt();
    for (;;)
    {
        //do nothing.interrupt routine will take charge
    }
}

// Port 4 interrupt service routine
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
    if(P4IFG&S1) { //check if S1 was pressed
        P4IFG &= ~S1;    // clear the interrupt flag
        PJOUT^=(LED0+LED1+LED2+LED3);//toggle leds on Port J
    }

    if(P4IFG&S2) { //check if S2 was pressed
        P4IFG &= ~S2;    // clear the interrupt flag
        P3OUT^=(LED4+LED5+LED6+LED7);//toggle leds on Port 3
    }

 }
Ishan Karve

About Ishan Karve

Ishan Karve is just an every day normal guy next door who happens to be an Electronics Engineer by profession and dabbles with PHP, Javascript, C++ and python. His interests vary as seasons change.. they change from astronomy to soul searching. This site is just a reflection of what he does to keep his mind engaged when he is not occupied by work and family. He is an extremely objective guy and is always ready for some good arguments.. of course over a glass of 40% proof alcohol.
This entry was posted in Electronics, MSP-GCC, MSP430 and tagged , , , , , , . Bookmark the permalink.

2 Responses to Fun with interrupts on MSP-EXP430FR5739 FRAM Experimenter Board

  1. erea says:

    Is posible make it without interrupts?

    thanks a lot

  2. erea says:

    Is possible make it without interrupts?

    thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *