首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中断发生时不调用WiringPi ISR吗?

中断发生时不调用WiringPi ISR吗?
EN

Stack Overflow用户
提问于 2019-04-25 15:22:21
回答 1查看 1.3K关注 0票数 0

我已经将我的覆盆子pi 1的GPIO引脚17(在WiringPi Pin17 =Pin0中)与中断源( IR -LEDemitter/接收器,每当红外线被某些障碍物中断时触发中断)连接。为了设置ISR,我一直在使用WiringPi库(我也已经在pigpio库中尝试过了,但我在那里也遇到了同样的问题)。为了验证我是否真的在Pin17上接收中断,我用我的逻辑分析仪进行了检查,正如您所看到的,这个引脚上肯定发生了一些中断:

下面是我的代码:

代码语言:javascript
复制
#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作为参考。那么我到底做错了什么呢?谢谢你给我的任何建议!

EN

回答 1

Stack Overflow用户

发布于 2019-07-11 23:10:29

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

因此,与其调用

wiringPiISR(INT_PIN, INT_FALLING_EDGE, &MyInterrupt)

打电话

wiringPiISR(INT_PIN, INT_FALLING_EDGE, MyInterrupt)

我的猜测是,这与wiringPiISR将该参数作为指针(* function )的事实有关,所以将调用地址放在它前面会导致在尝试调用MyInterrupt函数时发生一些奇怪的事情,对我来说,它导致了我的程序崩溃!

希望这能帮助/也许其他人能够更详细地解释为什么会发生这种情况。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55843898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档