【问题标题】:WiringPi ISR is not called although interrupts occur?尽管发生中断,但未调用 WiringPi ISR?
【发布时间】:2019-04-25 07:22:20
【问题描述】:

我已将我的树莓派 1 的 GPIO 引脚 17(在 WiringPi Pin17 = Pin0 中)与一个中断源(一个 IR-LED 发射器/接收器,每当红外线被某些障碍物中断时触发中断)连接。为了设置 ISR,我一直在使用 WiringPi 库(我已经用 pigpio 库尝试过,但我也有同样的问题)。 为了验证我确实在 Pin17 上接收到中断,我用我的逻辑分析仪进行了检查,你可以看到这个引脚上肯定发生了一些中断:

这是我的代码:

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

方法wiringPiSetup 和wiringPiISR 被成功调用并且没有返回错误。

我正在使用以下链接选项构建此示例:-lwiringPi -lm -lpthread。也许我缺少链接选项?

我一直使用this code here 作为参考。那么我在这里做错了什么?感谢您给我的任何建议!

【问题讨论】:

    标签: c raspberry-pi interrupt interrupt-handling wiringpi


    【解决方案1】:

    我不完全确定为什么,但我发现删除wiringPiISR 的函数调用输入前面的一元运算符解决了我的问题。

    所以不要调用

    wiringPiISR(INT_PIN, INT_FALLING_EDGE, &amp;MyInterrupt)

    打电话

    wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)

    我的猜测是,这与 wiringPiISR 将该参数作为指针 (*function) 的事实有关,因此将调用地址放在它前面会导致尝试和调用MyInterrupt 函数,对我来说它导致我的程序崩溃!

    希望这会有所帮助/也许其他人能够详细说明为什么会发生这种情况。

    【讨论】:

      猜你喜欢
      • 2020-11-19
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 2020-03-29
      • 2022-01-28
      • 1970-01-01
      相关资源
      最近更新 更多