2

I'm trying to get interrupts working on the Raspberry Pi using the wiringPi library. When using INT_EDGE_RISING the code below results in very few interrupts when operating the button. This is indicated by 3-5 printf's '.'.

But when using INT_EDGE_FALLING the interrupt seems to be called continuously as the code is printing an endless string of '.'. This rather looks like a level interrupt than an edge triggered one.

The GPIO is configured in my software only and the internal pull-up is enabled so I can be sure that it is not floating.

Now the question is why the interrupt is called continuously when pulling the pin to ground. And how do I get the code to call the interrupt only once when an edge is detected? I very much appreciate your help. Thanks.

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>

// pin defines (BCM2835 numbering)
#define BUTTON    17

void myInterrupt (void)
{
    printf("."); fflush (stdout);
}

int main (void)
{
    if (wiringPiSetupGpio () < 0)
    {
        fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
        return 1 ;
    }
    else
    {
            pinMode(BUTTON, INPUT);
            pullUpDnControl(BUTTON, PUD_UP);
    }

    if (wiringPiISR (BUTTON, INT_EDGE_FALLING, &myInterrupt) < 0)
    {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
        return 1 ;
    }

    for (;;)
    {
    }

    return 0 ;
}
5
  • That code works properly on my B+.
    – joan
    Oct 12, 2014 at 17:48
  • What do you have connected to the pin?
    – Milliways
    Oct 12, 2014 at 23:08
  • possible duplicate of WiringPi: Random Interrupts caused by PWM?
    – Milliways
    Oct 12, 2014 at 23:20
  • The input pin is directly connected to either 3V3 or GND via a jumper wire.
    – Soeren
    Oct 13, 2014 at 15:19
  • I'm afraid the most likely explanation is you have the wire attached to the wrong pin.
    – joan
    Oct 13, 2014 at 21:41

1 Answer 1

1

The solution to this is as follows:

I've changed the power supply which is rated 1500 mA to a different one and the glitches now are gone.

Thanks for all your input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.