Reputation: 441
I have connected GPIO Pin 17(in WiringPi Pin17 = Pin0) of my raspberry pi 1 with an interrupt source (an IR-LEDemitter/receiver which triggers an interrupt whenever the IR ray gets interrupted by some obstacle). For setting up the ISR, I have been using the WiringPi library (I have already tried it with the pigpio library as well, but I have the same problem there as well).
To verify that I am actually receiving interrupts on Pin17, I have checked it with my logic analyzer, and there are definitely some interrupts occuring on this pin as you can see:
Here is my code:
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <wiringPi.h>
#include "MCP3008Driver.h"
#include "DHT11.h"
#define INT_PIN 0
volatile int eventCounter = 0;
void myInterrupt(void){
printf("hello ISR!\n");
eventCounter++;
}
volatile sig_atomic_t stopFlag = 0;
static void stopHandler(int sign) { /* can be called asynchronously */
stopFlag = 1; /* set flag */
}
int main(void) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
// sets up the wiringPi library
if (wiringPiSetup () < 0) {
printf("Unable to setup wiring pi\n");
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror
(errno));
return 1;
}
// set Pin 17/0 to generate an interrupt on high-to-low transitions
// and attach myInterrupt() to the interrupt
if(wiringPiISR(INT_PIN, INT_EDGE_FALLING, &myInterrupt) < 0){
printf("unable to setup ISR\n");
fprintf(stderr, "Unable to setup ISR: %s\n", strerror(errno));
}
DHT11_data data;
configureSPI();
while(1){
if(stopFlag){
printf("\n Ctrl-C signal caught! \n");
printf("Closing application. \n");
return 0;
}
//read_dht_data(&data);
int analogBoiler = readChannel(0);
int analogHeater = readChannel(1);
int analogPress = readChannel(2);
int analogACS712 = readChannel(3);
int analogDynamo = readChannel(4);
printf("Channel 0 / Boiler = %f\n", evaluateChannelValue(ePT100_BOILER, analogBoiler));
printf("Channel 1 / Heater = %f\n", evaluateChannelValue(ePT100_HEATER, analogHeater));
printf("Channel 2 / Pressure = %f\n", evaluateChannelValue(ePRESS, analogPress));
printf("Channel 3 / Power ACS712 = %f\n", evaluateChannelValue(eACS712, analogACS712));
printf("Channel 4 / Power Dynamo = %f\n", evaluateChannelValue(eDYNAMO, analogDynamo));
//printf("Humidity Environment: %f\n", data.humidity);
//printf("Temperature (Celsius) Environment: %f\n", data.temp_celsius);
// display counter value every second.
printf("%d\n", eventCounter);
sleep(5);
}
return 0;
}
The methods wiringPiSetup and wiringPiISR are successfully called and are not returning an error.
I am building this example the the following linking options: -lwiringPi -lm -lpthread. Maybe I am missing a linking option?
I have been using this code here as a reference. So what am I doing wrong here? Thank you for any advice you can give me!
Upvotes: 0
Views: 2376
Reputation: 1
I'm not entirely sure why but I found that removing the unary operator in front of the function call input to wiringPiISR
solved my problems.
So instead of calling
wiringPiISR(INT_PIN, INT_FALLING_EDGE, &MyInterrupt)
call
wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)
My guess is that this has something to do with the fact the wiringPiISR
is taking that argument as pointer (*function) so putting the address of call in front of it causes something weird to happen when it goes to try and call the MyInterrupt
function, for me it caused my program to crash!
Hope this helps / maybe someone else will be able to elaborate more on why this would happen.
Upvotes: 0