Hi:
I want to use the button p1.1 of the launchpad msp430f5529. I'm using a 12 bits CAD at the same time and I programmed both interrupts. The problem is that when I push the button it doesn't get inside the service routine, could you please help me cause I'm new with MSP430 and I'm a little bit lost.
Note: The ADC12 is working correctly.
#include <stdio.h>
#include "inc/hw_memmap.h"
#include "adc12_a.h"
#include "wdt_a.h"
#include "gpio.h"
#include <msp430.h>
void main (void)
{
//Stop Watchdog Timer
WDT_A_hold(WDT_A_BASE);
////////////////////////////////////////////////////////////////////Interruption for the signal "ST"////////////////////////////////////////////////////////////////////////////////////////////
/*P1DIR |= 0x10; // Set P1.4 to output direction
P1IES |= 0x10; // P1.4 Hi/lo edge
P1IFG &= ~0x10; // P1.4 IFG cleared
P1IE |= 0x10; // P1.4 interrupt enabled
*/
P1DIR |= 0X02;
P1IES |= 0X02;
P1IFG &= ~0X02;
P1IE |= 0X02;
P1OUT = 0X01;
// Enter LPM4 w/interrupt
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//P6.0 ADC option select
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P6,
GPIO_PIN0
);
//CONFIGURATION OF THE PORT P1.0 WITH A LED
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN0
);
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN5
);
////////////////////////////////////////////////////////////////////////
//Initialize the ADC12_A_A Module
/*
* Base address of ADC12_A_A Module
* Use internal ADC12_A_A bit as sample/hold signal to start conversion
* USE MODOSC 5MHZ Digital Oscillator as clock source
* Use default clock divider of 1
*/
ADC12_A_init(ADC12_A_BASE,
ADC12_A_SAMPLEHOLDSOURCE_SC,
ADC12_A_CLOCKSOURCE_ADC12OSC,
ADC12_A_CLOCKDIVIDER_1);
ADC12_A_enable(ADC12_A_BASE);
/*
* Base address of ADC12_A_A Module
* For memory buffers 0-7 sample/hold for 64 clock cycles
* For m emory buffers 8-15 sample/hold for 4 clock cycles (default)
* Disable Multiple Sampling
*/
ADC12_A_setupSamplingTimer(ADC12_A_BASE,
ADC12_A_CYCLEHOLD_64_CYCLES,
ADC12_A_CYCLEHOLD_4_CYCLES,
ADC12_A_MULTIPLESAMPLESDISABLE);
//Configure Memory Buffer
/*
* Base address of the ADC12_A_A Module
* Configure memory buffer 0
* Map input A0 to memory buffer 0
* Vref+ = AVcc
* Vr- = AVss
* Memory buffer 0 is not the end of a sequence
*/
ADC12_A_memoryConfigure(ADC12_A_BASE,
ADC12_A_MEMORY_0,
ADC12_A_INPUT_A0,
ADC12_A_VREFPOS_AVCC,
ADC12_A_VREFNEG_AVSS,
ADC12_A_NOTENDOFSEQUENCE);
//Enable memory buffer 0 interrupt
ADC12_A_clearInterrupt(ADC12_A_BASE,
ADC12IFG0);
ADC12_A_enableInterrupt(ADC12_A_BASE,
ADC12IE0);
while (1)
{
//Enable/Start sampling and conversion
/*
* Base address of ADC12_A_A Module
* Start the conversion into memory buffer 0
* Use the single-channel, single-conversion mode
*/
ADC12_A_startConversion(ADC12_A_BASE,
ADC12_A_MEMORY_0,
ADC12_A_SINGLECHANNEL);
//LPM0, ADC12_A_ISR will force exit
//__bis_SR_register(LPM0_bits + GIE);
//ISR for ST
_BIS_SR(LPM4_bits + GIE);
//_EINT();
//P1DIR |= 0X20;
//P1OUT |= 0X20;
//for Debugger
//__no_operation();
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_A_ISR (void)
{
switch (__even_in_range(ADC12IV,34)){
case 0: break; //Vector 0: No interrupt
case 2: break; //Vector 2: ADC overflow
case 4: break; //Vector 4: ADC timing overflow
case 6: //Vector 6: ADC12IFG0
//Is Memory Buffer 0 = A0 > 0.5AVcc?
if (ADC12_A_getResults(ADC12_A_BASE,
ADC12_A_MEMORY_0)
>= 0x000){
//set P1.0
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
} else {
//Clear P1.0 LED off
GPIO_setOutputLowOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
}
//Exit active CPU
__bic_SR_register_on_exit(LPM0_bits);
case 8: break; //Vector 8: ADC12IFG1
case 10: break; //Vector 10: ADC12IFG2
case 12: break; //Vector 12: ADC12IFG3
case 14: break; //Vector 14: ADC12IFG4
case 16: break; //Vector 16: ADC12IFG5
case 18: break; //Vector 18: ADC12IFG6
case 20: break; //Vector 20: ADC12IFG7
case 22: break; //Vector 22: ADC12IFG8
case 24: break; //Vector 24: ADC12IFG9
case 26: break; //Vector 26: ADC12IFG10
case 28: break; //Vector 28: ADC12IFG11
case 30: break; //Vector 30: ADC12IFG12
case 32: break; //Vector 32: ADC12IFG13
case 34: break; //Vector 34: ADC12IFG14
default: break;
}
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN5
);
// P1.0 = toggle
P1IFG &= ~0x10;
// P1.4 IFG cleared
}