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 ;
}