tw1ns 0 Posted January 15, 2013 Share Posted January 15, 2013 Hello. Sorry for my bad english... I have some problems... how to using this code in Energia: attachInterrupt(0, func, CHANGE); Iam read this http://arduino.cc/en/Reference/AttachInterrupt But what is pin number i can use this msp430g2553? Quote Link to post Share on other sites
energia 485 Posted January 15, 2013 Share Posted January 15, 2013 Energia or rather the MSP430 only supports FALLING and RISING, not CHANGE. I guess CHANGE could be emulated but will introduce some overhead in the ISR. It might be worth looking into this for the next release. Quote Link to post Share on other sites
tw1ns 0 Posted January 15, 2013 Author Share Posted January 15, 2013 THX! This is bad news... Quote Link to post Share on other sites
pivden 6 Posted February 3, 2013 Share Posted February 3, 2013 You may try to use 2 pins with different modes of interrupts. - signal goes to the two pins at the same time; - interrupts in FALLING and RISING modes (FALLING for when the pin goes from high to low; RISING to trigger when the pin goes from low to high); - attachInterrupt() for different pins points to the same function attachInterrupt(5, func_interrupt_change, FALLING); attachInterrupt(6, func_interrupt_change, RISING); if I correctly understood CHANGE mode in Arduino for buttons: http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_PushButton (Fig. 2: Switch after debouncing circuit) Quote Link to post Share on other sites
roadrunner84 466 Posted February 3, 2013 Share Posted February 3, 2013 I'm not an Energia user myself, but I guess what you could do is add some code similar to this to the end of your interrupt function: if (readPin (5)==1) attachInterrupt(5, func_interrupt_change, FALLING); else attachInterrupt(5, func_interrupt_change, RISING); Quote Link to post Share on other sites
energia 485 Posted February 11, 2013 Share Posted February 11, 2013 While looking at this I discovered a serious bug in the interrupt code. Basically RISING would never work. Patch for this fix is pretty simple: diff --git a/hardware/msp430/cores/msp430/Energia.h b/hardware/msp430/cores/msp430/Energia.h index facfd06..7ce8034 100644 --- a/hardware/msp430/cores/msp430/Energia.h +++ b/hardware/msp430/cores/msp430/Energia.h @@ -22,9 +22,8 @@ extern "C"{ #define LSBFIRST 0 #define MSBFIRST 1 -#define CHANGE 1 -#define FALLING 2 -#define RISING 3 +#define RISING 0 +#define FALLING 1 #define INPUT 0x0 #define OUTPUT 0x1 And this is the Sketch that I used to test it. This Sketch also demonstrates how to get an interrupt on CHANGE just like in Arduino. It's only a couple more lines of code and a volatile var. uint8_t volatile edge; void setup() { pinMode(RED_LED, OUTPUT); digitalWrite(RED_LED, LOW); attachInterrupt(PUSH2, func, FALLING); edge = FALLING; } void loop() { } void func() { if(edge == FALLING) { attachInterrupt(PUSH2, func, RISING); edge = RISING; } else { attachInterrupt(PUSH2, func, FALLING); edge = FALLING; } P1OUT ^= 0x01; } calinp and bluehash 2 Quote Link to post Share on other sites
Dviselman 0 Posted June 25, 2013 Share Posted June 25, 2013 While looking at this I discovered a serious bug in the interrupt code. Basically RISING would never work. Patch for this fix is pretty simple: diff --git a/hardware/msp430/cores/msp430/Energia.h b/hardware/msp430/cores/msp430/Energia.h index facfd06..7ce8034 100644 --- a/hardware/msp430/cores/msp430/Energia.h +++ b/hardware/msp430/cores/msp430/Energia.h @@ -22,9 +22,8 @@ extern "C"{ #define LSBFIRST 0 #define MSBFIRST 1 -#define CHANGE 1 -#define FALLING 2 -#define RISING 3 +#define RISING 0 +#define FALLING 1 #define INPUT 0x0 #define OUTPUT 0x1 Where do I go to make this fix? (working on a mac). Thanks in advance, Dan Quote Link to post Share on other sites
energia 485 Posted June 26, 2013 Share Posted June 26, 2013 The MSP430 does not have a CHANGE interrupt. The fix is so that FALLING and RISING have the correct value. You can apply this fix by doing the following: 1: control click Energia and select "Show Package Content". This will open the Energia folder. 2: go to Contents/Resources/Java/hardware/msp430/cores 3: In that folder locate Energia.h and open it in a TextEdit 4: Replace: #define CHANGE 1 #define FALLING 2 #define RISING 3 with #define FALLING 1 #define RISING 2 5: Save and close TextEdit The trick now is to emulate the CHANGE interrupt. The example Sketch I posted above shows how to do this. The Sketch demonstrates that if you push button 2 the LED goes on and when you release it it goes off. The idea is that when you enter the interrupt handler in this case func() you flip the edge of the interrupt. So if it was triggering on FALLING you reattach the interrupt on the RISING edge and vise versa. Make sure that the variable that keeps track of the edge is of type volatile in this case volatile uint8_t edge. Robert Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.