This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
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
}
Sorry I just put everything but the important part for the button interrupt is:
#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);
//Configuration for p1.1 button interrupt
P1DIR |= 0X02;
P1IES |= 0X02;
P1IFG &= ~0X02;
P1IE |= 0X02;
P1OUT = 0X01;
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN5
);
while (1)
{
_BIS_SR(LPM4_bits + GIE);
}
// 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
}
Can you please Help me????
Thanks a lot
Gael Sande Avenda��o said:P1IFG &= ~0x10; // P1.4 IFG cleared
P1IFG &= ~0x02;
hopefully it might resolve the issue. Note, you have clear this flag every time you serve an ISR to allow subsequent interrupts.
Cheers.
Hi Gael,
Now, I think your problem is pin pointed. If I were you, I will start working as below.
1. I will check , weather Button port is initially in high state? pulled up or not? if yes then check by CRO or MM
2. I will check weather button press is resulting in low on the port? In your case it is Bit2 of port 1.
This is because you have (HIgh to low interrupt edge P1IEs = 0x02).
3. You should get your answer by now. If the about conditions were true then to furthur investigate
a. enter debug mode
b. insert NOP in main loop
while (1) { _nop(); // Just put a no operation here //and commnet out this low power mode. //_BIS_SR(LPM4_bits + GIE); }
c. set break point at this line
//P1OUT = 0X01; change this to P1OUT |= 0X01; // set break point here
d. Open registers in CCS and see the PIFG register in Port1.
e. Press button and hold. Press F6 to single step, at this stage P1IFG should change. and BIT2 should be set.
This funnel down structure, will help you further in solving a lot of issues. This is my experience any way. I am just sharing to help you.
cheers.
Hi,
P1DIR |= 0X02; means, consider P1.1 as Output.....
So to make sure p1.1 is input P1DIR &= ~ 0x02
Have fun
NBA
You configure P1.1 to trigger an interrupt, but in your port ISR, you clear the interrupt of P1.4. So the IFG of P1.1 stays set, causing an eternal interrupt loop.
If you don’t get an interrupt at all, then perhaps you don’t have a pull-up on the port pin? Pressing the button then doesn’t cause a port pin edge.
Also, you switch P1.1 to low output, so there won’t be an edge unless your button shorts the pin to VCC (in which case you waste lots of power).
P1DIR =0; // all pins input !
P1OUT=0x02; // high level for internal pull-up on P1.1
P1REN=0x02; // enable internal pull-up on P1.1
I don't know why but it's still not working. Even though I used an external buttun to simulate it and it's woirkin properly so don't worry.
Many thnaks for your answers ;).
I think he forgot the Pull Up/Down resistor.So once again
// Set as output to avoid triggering the interrupt P1DIR |= 0x02; // Select wanted interrupt slope P1IES |= 0x02; // Use pulldown / Up resistor depends on the state of P1OUT P1REN |= 0x02; // Now what happens if you press the button? tie it to GND or VCC ? // I never had a launchpad so i dont know but // if putton pressed = GND on the connector use P1OUT |= 0x02; (Pull up resistor) otherwise P1OUT & = 0x02; (Pulldown) // so put here the right P1OUT state // Now Enable interrupt for that pin P1IE |= 0x02; // Clear the Flag for that pin P1IFG &= ~0x02; // now you can safely set the pin as input again if i remember right P1DIR &= ~0x02;
hope this will help
Have fun
NBA
**Attention** This is a public forum