Maybe when you want to test an application (a simple one), you would like to use board features to interact with the program. In the case of MSP-EXP430FR5739 there are two switches and eight LEDs.

The most common simple program to start using switches and LEDs, it is a software polling over one of those switches to toggle a led. This is done configuring pins as inputs/outputs and pull-up or pull-down resistors. Here is another approach: Switch handling is made using interrupts and configuration is done using TI’s driverlib.

/*
 * msp430fr5739_simple_template.c
 *
 *  Created on: Jun 30, 2015
 *      Author: Gustavo Velasco-Hernandez
 *       Email: gustavo.velascoh@gmail.com
 */

/** Simple program to interfacing with MSP-EXP430FR5739 using driverlib.
* handling of inputs switches by interrupts and configuring leds as outputs.
**/

#include <driverlib.h>

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	
    //Set P3.7 - P3.4 to output direction (Leds 7 - 4)
    GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN7);
    GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN6);
    GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN5);
    GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN4);
    GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);
    GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN6);
    GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);
    GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN4);

    //Set PJ.3 - PJ.0 to output direction (Leds 3 - 0)
    GPIO_setAsOutputPin(GPIO_PORT_PJ,GPIO_PIN3);
    GPIO_setAsOutputPin(GPIO_PORT_PJ,GPIO_PIN2);
    GPIO_setAsOutputPin(GPIO_PORT_PJ,GPIO_PIN1);
    GPIO_setAsOutputPin(GPIO_PORT_PJ,GPIO_PIN0);
    GPIO_setOutputLowOnPin(GPIO_PORT_PJ,GPIO_PIN3);
    GPIO_setOutputLowOnPin(GPIO_PORT_PJ,GPIO_PIN2);
    GPIO_setOutputLowOnPin(GPIO_PORT_PJ,GPIO_PIN1);
    GPIO_setOutputLowOnPin(GPIO_PORT_PJ,GPIO_PIN0)


    //Enable P4.0, P4.1 internal resistance as pull-Up resistance
    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4,GPIO_PIN0);
    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4,GPIO_PIN1);

    //P4.0, P4.1 interrupt enabled
    GPIO_enableInterrupt(GPIO_PORT_P4,GPIO_PIN0);
    GPIO_enableInterrupt(GPIO_PORT_P4,GPIO_PIN1);

    //P4.0, P4.1 Hi/Lo edge
    GPIO_selectInterruptEdge(GPIO_PORT_P4,GPIO_PIN0,GPIO_HIGH_TO_LOW_TRANSITION);
    GPIO_selectInterruptEdge(GPIO_PORT_P4,GPIO_PIN1,GPIO_HIGH_TO_LOW_TRANSITION);

    //P4.0, P4.1 IFG cleared
    GPIO_clearInterrupt(GPIO_PORT_P4,GPIO_PIN0);

    GPIO_clearInterrupt(GPIO_PORT_P4,GPIO_PIN1);

    //Enter LPM4 w/interrupt
    __bis_SR_register(LPM4_bits + GIE);

    //For debugger
    __no_operation();

}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT4_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(PORT4_VECTOR)))
#endif
void Port_4(void)
{
	switch(__even_in_range(P4IV,0x10))
	{
	case P4IV_P4IFG0:
		//P1.0 = toggle
		GPIO_toggleOutputOnPin(
			GPIO_PORT_P3,
			GPIO_PIN7
			);

		//P1.4 IFG cleared
		GPIO_clearInterrupt(
			GPIO_PORT_P4,
			GPIO_PIN0
			);
		break;
	case P4IV_P4IFG1:
		//P1.0 = toggle
		GPIO_toggleOutputOnPin(
			GPIO_PORT_PJ,
			GPIO_PIN0
			);

		//P1.4 IFG cleared
		GPIO_clearInterrupt(
			GPIO_PORT_P4,
			GPIO_PIN0
			);
		break;
	}
}
Advertisements