chipKIT® Development Platform

Inspired by Arduino™

Fubarino SD -attachInterrupt( )-help-please

Created Sun, 28 Jul 2013 01:45:42 +0000 by Omnimusha


Omnimusha

Sun, 28 Jul 2013 01:45:42 +0000

Hi, I have connected in this way and with this code, but does not work, I'm doing wrong?

attachInterrupt function (interrupt, function, mode), the interrupt, numbers 0 (pin 2) or, interrupt, numbers 0 (pin 0)?

volatile uint8_t state = LOW;


void setup()
{
  Serial.begin(9600);
  attachInterrupt(0, rpm, RISING );
}

void loop()
{
  
}

void rpm()
{
  state = !state;
  Serial.println(state);
}

[url]http://sia1.subirimagenes.net/img/2013/07/28/13072803390375227.png[/url]


jmlynesjr

Sun, 28 Jul 2013 02:06:00 +0000

The manual says Pin 0 is INT1, so try... attachInterrupt(1, rpm, RISING );

Also, connect to Pin 0 not Pin2.

James


Omnimusha

Sun, 28 Jul 2013 03:01:17 +0000

The manual says Pin 0 is INT1, so try... attachInterrupt(1, rpm, RISING ); Also, connect to Pin 0 not Pin2. James

not working :?


jmlynesjr

Mon, 29 Jul 2013 01:55:44 +0000

Try this example from the SD wiki.

James

// This sketch shows one way to use an external interrupt pin on
// the FubarinoSD board. (There are 5 external interrupts on PIC32:
// INT0 = Pin4, INT1 = Pin0, INT2 = Pin1, INT3 = Pin2, INT4 = Pin3)
// To run this test, you must take a wire and connect pin 12 to
// pin 0 (INT1). We then toggle pin 12 as an output to stimulate
// an external interrupt occuring on pin 0 (INT1).
// When a RISING edge is detected on INT1 (pin0), the attached
// function (intButton()) will get called. In that function we
// toggle the LED. So if you have the wire from pin 12 to pin 0,
// and you run this sketch, you should see the LED blinking.

#define pinSrc 12 // used as external interrupt stimulator
#define pinInt PIN_INT1  // The extern interrupt we choose to use (pin0)

void intHandle();

void setup() 
{
  digitalWrite(PIN_LED1, LOW);      // Start of with LED off
  pinMode(PIN_LED1, OUTPUT);        // Make LED pin an output
  pinMode(pinInt, INPUT);           // Interrupt pin must be an input
  digitalWrite(pinSrc, LOW);        // Simulator pin must start low
  pinMode(pinSrc, OUTPUT);          // And stim pin must be output too
  attachInterrupt(1, intHandle, RISING); // Register interrupt function on Int1
}

void loop() 
{
   digitalWrite(pinSrc, HIGH);      // Set stim pin high (triggers interrupt)
   delay(500);                      // wait half a second
   digitalWrite(pinSrc, LOW);       // Set stim pin low
   delay(500);                      // wait another half second
}

// This function gets called when an external interrupt occurs
void intHandle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
}

Omnimusha

Mon, 29 Jul 2013 19:10:43 +0000

now it works, thanks for your help [color=#400000]James[/color]


jmlynesjr

Mon, 29 Jul 2013 23:47:24 +0000

Great!

I'm guessing it was setting the interrupt pin as an input, which wasn't in your test code.

Glad you have it working now.

James


Jacob Christ

Tue, 14 Jun 2016 18:26:58 +0000

Be careful not to do what I did and use LOW or HIGH instead of FALLING or RISING!

Jacob

From Brian Schmalz:

The line: attachInterrupt(COIN_COUNTER, intHandle, LOW); needs to be changed to attachInterrupt(1, intHandle, RISING); and then it will work.

The reason for the two changes:

  1. Even though you call "pinMode(COIN_COUNTER, INPUT);" with COIN_COUNTER being 0 (a pin number), you need to use the "interrupt number" (i.e. INT1, or "1") as an argument to attachInterrupt(). I don't know why, that's just the way it is. :-)

  2. We don't have code right now to do LOW or HIGH level interrupts, we only support RISING or FALLING as edge types (second parameter).

If you make that change, it will work as you expect. If RISING is not the right value for your coin mech, use FALLING.