Other Parts Discussed in Thread: MSP430G2553
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 Caio,
thanks for your questions.
Let me quickly clarify some open items to help identify the problem:
"The only change I made was to add in the registers 1 led (where it is output), plus 1 button on the input."
To me it looks like the interrupt is not being triggered (as you say nothings happening). So did you also enable the interrupt for the pin that is connected to your button? Plus then resetting the according interrupt flag?
I also saw that the P1IES |= BIT3 stayed a bit unclear so let me try to shed some light on it: the PxIES register allows you to select the edge of the input signal, i.e. rising or falling edge, to trigger an interrupt. You'll use this because you could have buttons that are connected to Ground or Vcc and a push results in different edges then. Hope this helps.
Also, you said that sometimes using the code to always poll for an interrupt you won't get a response. Depending on the scenerio that you observe this behaviour it might be due to a missing debounce time interval (essentially that the device cannot be interrupted due to an interrupt before). Please share details when you experience response-issues on your button so that I can further help you solve this.
Best regards,
Britta
You have a few things that need attention:
* Your ISR logic is wrong: You should never ever have a "while(1)" loop in any ISR.
* The way you check for which pin triggered the interrupt is wrong: Do not use "P1IN" (if you think if debouncing you will know why). Instead you should use "P1IFG" to check for the triggering pin (this is the purpose of the IFG register).
* You should handle debouncing with either firmware or hardware whenever you have button input.
So, I would rewrite the ISR as follows:
#pragma vector = PORT1_VECTOR
__interrupt void port_1_ISR(void){
if(P1IFG & BIT3){
LED1 = ON/OFF; //turn ON or OFF the LED as needed
P1IFG &= ~BIT3; //clear the flag
}
//assuming your 2nd button is on BIT4 of PORT1
if(P1IFG & BIT4){
LED2 = ON/OFF; //turn ON or OFF the LED as needed
P1IFG &= ~BIT4; //clear the flag
}
}
**Attention** This is a public forum