Jump to content


Photo

attachInterrupt example in CC3200

CC3200 Interrupt attachInterrupt

  • Please log in to reply
6 replies to this topic

#1 ZenClide

ZenClide

    Noob Class

  • Members
  • 5 posts

Posted 10 January 2017 - 07:28 PM

Hello!

 

I recently started playing with Energia and the CC3200 LaunchPad. I tried the example for "attachInterrupt" in the link: http://energia.nu/re...ttachinterrupt/

 

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!
 


#2 Rei Vilo

Rei Vilo

    Level 4

  • Members
  • 1,218 posts
  • LocationFrance

Posted 10 January 2017 - 07:53 PM

Use INPUT_PULLUP instead of INPUT.

 

See pinMode() and INPUT_PULLUP at Energia.nu.


  • ZenClide likes this

#3 ZenClide

ZenClide

    Noob Class

  • Members
  • 5 posts

Posted 11 January 2017 - 10:00 PM

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?



#4 Fmilburn

Fmilburn

    Level 3

  • Members
  • 497 posts
  • LocationSeattle

Posted 12 January 2017 - 01:50 AM

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:

Attached File  CC3200_button_test.jpg   117.5KB   0 downloads

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 likes this

#5 ZenClide

ZenClide

    Noob Class

  • Members
  • 5 posts

Posted 12 January 2017 - 06:59 PM

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! :D


#6 Fmilburn

Fmilburn

    Level 3

  • Members
  • 497 posts
  • LocationSeattle

Posted 12 January 2017 - 09:21 PM

@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/wo...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 likes this

#7 ZenClide

ZenClide

    Noob Class

  • Members
  • 5 posts

Posted 13 January 2017 - 02:52 AM

Thank You! I did not know this







Also tagged with one or more of these keywords: CC3200, Interrupt, attachInterrupt

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users