ZenClide 0 Posted January 10, 2017 Share Posted January 10, 2017 Hello! I recently started playing with Energia and the CC3200 LaunchPad. I tried the example for "attachInterrupt" in the link: http://energia.nu/reference/attachinterrupt/ I changed the code a little by modifying pinMode and attachIntterrupt #define PUSH 4 ... pinMode(PUSH, INPUT); // I want Pin 4 as my interrupt or SW3 on the board, only Input because the board has a pull down resistor already attachInterrupt(PUSH, blink, FALLING); } void loop() { ... } When I run this example, the interrupt is serviced multiple times at random without me touching the button. I wanted to know if anybody else has encountered the same problem or could someone try it and let me know if the interrupt works for them? I'm not sure what I'm doing wrong. Any advice is welcomed! Thank You! Quote Link to post Share on other sites
Rei Vilo 695 Posted January 10, 2017 Share Posted January 10, 2017 Use INPUT_PULLUP instead of INPUT. See pinMode() and INPUT_PULLUP at Energia.nu. ZenClide 1 Quote Link to post Share on other sites
ZenClide 0 Posted January 11, 2017 Author Share Posted January 11, 2017 Use INPUT_PULLUP instead of INPUT. See pinMode() and INPUT_PULLUP at Energia.nu. That doesn't work for me . The LED stays on and nothing happens when I pressed the button, I think that might be because of the external pulldown resistor on the board? Quote Link to post Share on other sites
Fmilburn 445 Posted January 12, 2017 Share Posted January 12, 2017 Hi @@ZenClide I tried it just now on a CC3200, Energia V17 without EMT and it worked fine other than the expected bounce from the switch... I hooked up a pushbutton switch to pin 4 and ground (without a pullup) as shown in the photo below: I used the following sketch: #define PUSH4 4 volatile int state = HIGH; volatile int flag = HIGH; int count = 0; void setup() { Serial.begin(9600); pinMode(GREEN_LED, OUTPUT); digitalWrite(GREEN_LED, state); /* Enable internal pullup. * Without the pin will float and the example will not work */ pinMode(PUSH4, INPUT_PULLUP); attachInterrupt(PUSH4, blink, FALLING); // Interrupt is fired whenever button is pressed } void loop() { digitalWrite(GREEN_LED, state); //LED starts ON if(flag) { count++; Serial.println(count); flag = LOW; } } void blink() { state = !state; flag = HIGH; } ZenClide 1 Quote Link to post Share on other sites
ZenClide 0 Posted January 12, 2017 Author Share Posted January 12, 2017 I tried the same setup and did not work, i tried with and without EMT. So I looked around in the libraries to see the pin configurations, I found a file called pins_energia.h in which I found the following structure: const uint16_t digital_pin_to_pin_num[] = { NOT_A_PIN, /* dummy */ NOT_A_PIN, /* 1 - 3.3V */ PIN_58, /* 2 - GPIO_03 */ PIN_04, /* 3 - GPIO_13 */ PIN_03, /* 4 - GPIO_12 */ PIN_61, /* 5 - GPIO_06 */ PIN_59, /* 6 - GPIO_04 */ PIN_05, /* 7 - GPIO_14 */ PIN_62, /* 8 - GPIO_07 */ PIN_01, /* 9 - GPIO_10 */ PIN_02, /* 10 - GPIO_11 */ PIN_15, /* 11 - GPIO_22 */ PIN_55, /* 12 - GPIO_01 */ PIN_21, /* 13 - GPIO_25 */ PIN_06, /* 14 - GPIO_15 */ PIN_07, /* 15 - GPIO_16 */ NOT_A_PIN, /* 16 - RESET */ PIN_45, /* 17 - GPIO_31 */ PIN_08, /* 18 - GPIO_17 */ PIN_18, /* 19 - GPIO_28 */ NOT_A_PIN, /* 20 - GND */ NOT_A_PIN, /* 21 - 5V */ NOT_A_PIN, /* 22 - GND */ PIN_57, /* 23 - GPIO_02 */ PIN_60, /* 24 - GPIO_05 */ PIN_58, /* 25 - GPIO_03 */ PIN_59, /* 26 - GPIO_04 */ PIN_63, /* 27 - GPIO_08 */ PIN_53, /* 28 - GPIO_30 */ PIN_64, /* 29 - GPIO_09 */ PIN_50, /* 30 - GPIO_00 */ PIN_17, /* 31 - GPIO_24 */ PIN_16, /* 32 - GPIO_23 */ PIN_60, /* 33 - GPIO_05 */ PIN_62, /* 34 - GPIO_07 */ PIN_18, /* 35 - GPIO_28 */ PIN_21, /* 36 - GPIO_25 */ PIN_64, /* 37 - GPIO_09 */ PIN_17, /* 38 - GPIO_24 */ PIN_01, /* 39 - GPIO_10 */ PIN_02 /* 40 - GPIO_11 */ }; From this, instead of using #define PUSH4 4 I used #define PUSH4 3 and it worked! I'm not sure why it is different, could it be an older version? Nonetheless it works! Thank You! Quote Link to post Share on other sites
Fmilburn 445 Posted January 12, 2017 Share Posted January 12, 2017 @@ZenClide The labels can be confusing. Energia uses a pin numbering system that is consistent on all boards. It starts with 3V3 (number 1) in the upper left, goes down to number 10 at lower left, and then starts up again on the other side at the bottom. See for example the pin map at Energia for the CC3200: http://energia.nu/wordpress/wp-content/uploads/2014/06/LaunchPads-CC3200-%E2%80%94-Pins-Maps-12-28.jpeg The pin map excerpt you have posted shows the same pin numbers right after the /* comments. So, pin 4 in Energia on the CC3200 is the same one that is labelled P03 on the board. Energia pin 3 is labelled P04 on the board. For Energia always use the Energia pin map and not the PCB labels. The CC3200 User Manual refers to the PCB labels as the "Dev Pin#". Use of port.pin type markings on LaunchPads has been deprecated in Energia. ZenClide 1 Quote Link to post Share on other sites
ZenClide 0 Posted January 13, 2017 Author Share Posted January 13, 2017 Thank You! I did not know this 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.