Jump to content
Sign in to follow this  
jcR

attachInterrupt on Stellaris Launchpad

Recommended Posts

Whats are the  pins and Interrupts for Stellarich Launchpad to use with this  function:

 

attachInterrupt(interrupt, function, mode)

Thanks 

JCR

Share this post


Link to post
Share on other sites

Hello JCR,

 

Contrary to arduino documentation on Stellaris you can use all  GPIO pins as first argument of the "attachinterrupt function"

 

ex:

attachInterrupt (PB_3, isrFunction, mode);

Here is an example using PUSH1  on PF_4 that toggle RED_LED

 

/*
  Test interruption et antirebond
*/
unsigned long DebounceTime;
unsigned long LastDebounceTime = 0;
volatile int FlagStateRedLed = LOW;
volatile int FlagStateGreenLed = LOW;

void setup()
{
Serial.begin(9600); 
pinMode(RED_LED, OUTPUT);
pinMode(PUSH1, INPUT_PULLUP);

attachInterrupt(PUSH1, ChangeStateRedLed, FALLING);
}

void loop()
{
  for (int i = 0; i < 100; i++) {
   Serial.println(" Waiting for push1 pressed");
    delay(10);
  }
}

void ChangeStateRedLed()
{
  DebounceTime = millis();
  
  if ( DebounceTime - LastDebounceTime > 200 || 
       DebounceTime < LastDebounceTime) {
    FlagStateRedLed = !FlagStateRedLed;
    digitalWrite(RED_LED, FlagStateRedLed);
    LastDebounceTime = DebounceTime;
  }
} 

Hope this help

 

Cheers

 

Bernard

Share this post


Link to post
Share on other sites

Hi Bernard

thanks for the response.

I have tested the following (not good for interrupt but ok for demo!)

 

 

volatile int state = HIGH;
 
void setup()
{
  Serial.begin(9600);
  pinMode(RED_LED, OUTPUT);
  attachInterrupt(RED_LED, blink, CHANGE);
}
 
void loop()
{
  digitalWrite(RED_LED, state);
  
}
 
void blink()
{
  state = !state;
  Serial.println("T");
  delay(50);
}

Share this post


Link to post
Share on other sites

Hi

 

This is why I asked the question.
Documentation of the arduino is not functioning with the Stellaris Launchpad and   brownfox gave me a solution that works perfectly.
JC
@ brownfox
who  did you find the solution ?

Share this post


Link to post
Share on other sites

Hi,

 

Sometimes using Arduino doc for Stellaris is confusing.

 

Arduino interrupts are numbered

 

Board	      int.0  int.1   int.2   int.3   int.4	int.5
Uno, Ethernet	2	3
Mega2560	2	3	21	20	19	18
Leonardo	3	2	0	1

Having a look at   WInterrupts.c  helped me to understand  attachInterrupt function on Stellaris

 

void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
        uint8_t bit = digitalPinToBitMask(interruptNum);
	uint8_t port = digitalPinToPort(interruptNum);
	uint32_t portBase = (uint32_t) portBASERegister(port);

So on Stellaris we use pin name.

Maybe interruptNum should be replaced by interruptPin ... just a suggestion. That being said I like Energia :D

In the exemple above ( PUSH1,  PF_4,  31) refer to  the same pin ( see  pins_energia.h)

 

Cheers

Bernard

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...