<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Using Interrupts</title>
		<link>http://forums.leaflabs.com/topic.php?id=9473</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:21:40 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=9473" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20945</link>
			<pubDate>Sat, 10 Nov 2012 05:51:25 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20945@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - There error message is accurate and complete. &#60;/p&#62;
&#60;p&#62;There is no member of &#60;code&#62;class voieRC&#60;/code&#62; called &#60;code&#62;ptr&#60;/code&#62;, and if there were, it could not be a member, it must be a static member function, or pointer to a simple function.&#60;/p&#62;
&#60;p&#62;Maybe you should solve the problem using C first, rather than introduce an extra source of bugs and misunderstanding?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20936</link>
			<pubDate>Sat, 10 Nov 2012 03:26:50 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20936@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thank you for your clarification.&#60;br /&#62;
I noticed that determine which pin triggered an interrupt can be a bit complicated.&#60;br /&#62;
My knowledge of register management are limited. I do not engage in this way for now. But if there is a tutorial to do some testing, I'm interested.&#60;/p&#62;
&#60;p&#62;I looked for a solution using C++ classes:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;quot;voieRC.h&#38;quot;
#define Serial SerialUSB

voieRC bouton(20);

void setup() {
  attachInterrupt(20, bouton.*ptr, CHANGE);
  // Ne fonctionne pas : error: invalid use of non-static member function
}

void loop() {
  SerialUSB.println(bouton.valeur());
  delay(500);
}

voieRC::voieRC(int pin){
  pinRC = pin;
  pinMode(pin, INPUT_PULLUP);
}

unsigned int voieRC::valeur() const{
  return (timeDOWN - timeUP);
}

void voieRC::etat() {
  if (digitalRead(this-&#38;gt;pinRC) == HIGH) {  // Front montant
    timeUP = micros();
    timeDOWN = micros();
  }
  else {  // Front descendant
    timeDOWN = micros();
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;With voieRC.h =&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;class voieRC{
  public:
  voieRC(int);

  unsigned int valeur() const;
  void etat();

  private:
  int pinRC;
  unsigned int timeUP;
  unsigned int timeDOWN;
};&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I get a compilation error:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;attachInterrupt(20, bouton.*ptr, CHANGE);
  // error: invalid use of non-static member function&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I tried to &#34;cast&#34; the pointer recover:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void (voieRC::*ptr)() = &#38;amp;voieRC::etat; //On déclare un pointeur sur la fonction membre
voieRC bouton(20);

void setup() {
  void (*ptrw)() = (void (*)()) bouton.*ptr;
  // Ne fonctionne pas : error: invalid cast from type &#38;#39;voieRC&#38;#39; to type &#38;#39;void (*)()&#38;#39;
  attachInterrupt(20, *ptrw, CHANGE);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;But it does not.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20926</link>
			<pubDate>Fri, 09 Nov 2012 18:22:22 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20926@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - figuring out which pin triggered an interrupt can be a bit involved.&#60;/p&#62;
&#60;p&#62;The easiest way is to have a different interrupt handler for each pin:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;volatile int state_pin20 = LOW;
volatile int state_pin21 = LOW; 

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(20, INPUT);
    attachInterrupt(20, blink, CHANGE);
    pinMode(21, INPUT);
    attachInterrupt(21, blink, CHANGE);
}

void loop() {
    digitalWrite(BOARD_LED_PIN, (state_pin20 &#124;&#124; state_pin21));
}
void blink20() {
  // pin had interrupt

        state_pin20 = !state_pin20;
}
void blink21() {
  // pin had an interrupt
        state_pin21 = !state_pin21;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Could you ue that approach?&#60;/p&#62;
&#60;p&#62;If not, you need to look in EXTI_PR register.&#60;br /&#62;
The way interrupt pins are set up is a bit odd. There is not a unique pin interrupt id for every pin.&#60;/p&#62;
&#60;p&#62;I/O pins are grouped into 16-pin ports, and a Maple has several ports.&#60;br /&#62;
To figure out which pin has triggered, you'll need to figure out which port, and pin within that port, a Maple pin number corresponds to. &#60;/p&#62;
&#60;p&#62;There is a table at &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#gpio-port-pin-map&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#gpio-port-pin-map&#60;/a&#62;&#60;br /&#62;
which tells you.&#60;/p&#62;
&#60;p&#62;IIRC, all the pin 0's on all ports share 1 set of trigger control and flags.&#60;br /&#62;
All the pin 1's on all ports share a 2nd set of trigger control and flags.&#60;br /&#62;
and so on&#60;br /&#62;
So once you know the pin number within the port, you can check that flag within EXTI_PR.&#60;br /&#62;
This is all described in loving detail in the STM32F103 RM0008 manual, which you can download from ST Micro.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20899</link>
			<pubDate>Fri, 09 Nov 2012 00:45:59 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20899@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Sorry if I was not specific enough.&#60;br /&#62;
I rephrase my question:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;volatile int state_pin20 = LOW;
volatile int state_pin21 = LOW; 

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(20, INPUT);
    attachInterrupt(20, blink, CHANGE);
    pinMode(21, INPUT);
    attachInterrupt(21, blink, CHANGE);
}

void loop() {
    digitalWrite(BOARD_LED_PIN, (state_pin20 &#124;&#124; state_pin21));
}
void blink() {
  // test pin has an interrupt

  if (pin20) {  // How to test here to see the pin20 triggered interrupt? ...
        state_pin20 = !state_pin20;
    }

  if (pin21) {  how to test here? ...
        state_pin21 = !state_pin21;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;thank you for your help
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20894</link>
			<pubDate>Thu, 08 Nov 2012 19:42:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20894@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 -&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;In the blink function, is it possible to know what has triggered the interrupt pin?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I don't think I understand the question.&#60;/p&#62;
&#60;p&#62;Are you asking:&#60;br /&#62;
A. &#34;can the interrupt service routine (blink) work out which pin triggered the interrupt that called the (blink) function&#34;, or&#60;br /&#62;
B. &#34;what kind of signal triggered the pin, was it a rising edge, falling edge, ...&#34; or&#60;br /&#62;
C. something else?&#60;/p&#62;
&#60;p&#62;BTW&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void blink() {

  // test pin has an interrupt
  // ?????

    if (state == HIGH) {
        state = LOW;
    } else { // state must be LOW
        state = HIGH;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;can be rewritten as:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void blink() {

  // test pin has an interrupt
  // ?????
  state = !state;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Using Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9473#post-20874</link>
			<pubDate>Thu, 08 Nov 2012 04:39:01 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20874@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;in this example :&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;volatile int state = LOW; 

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(20, INPUT);
    attachInterrupt(20, blink, CHANGE);
    pinMode(21, INPUT);
    attachInterrupt(21, blink, CHANGE);
}

void loop() {
    digitalWrite(BOARD_LED_PIN, state);
}

void blink() {

  // test pin has an interrupt
  // ?????

    if (state == HIGH) {
        state = LOW;
    } else { // state must be LOW
        state = HIGH;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Blink function is attached to two interruptions for pins 20 and 21 :&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;attachInterrupt(20, blink, CHANGE);
    attachInterrupt(21, blink, CHANGE);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;In the blink function, is it possible to know what has triggered the interrupt pin?&#60;/p&#62;
&#60;p&#62;Thank you for your answers
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
