I'm trying to control nexa units with RF-modules connected to a raspberry pi and have written a little program in C to sniff the transmitted message from the nexa remote control. The software uses an interrupt triggered on both rising and falling edges. What puzzles me is that while I expect 660 invocations of the ISR, it's usually several hundred thousand calls (sometimes more than a million). I do detect 660 bits or thereabouts, if I compare the state with the previously state and only register the time when the state is changing. If I run the program without sending a message from the remote there is zero bits and zero ISR-calls, unless I have the WIFI-dongle close to the RF-module. So I assume that WIFI interfere with the RF-signal. Also, the receiving module is powered with 3V3, though it is labeled with 5V. My question is: can an interrupt be generated on the falling edge and the port still be in a high state and vice versa?
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <wiringPi.h>
#define PORT 4
#define MAX_T 100
#define BUF_SIZE 1000
static struct timespec rec[BUF_SIZE];
volatile static int n=0;
volatile static int prevx=0;
volatile static int tot=0;
void ISR(){
tot++;//count the number of calls
//read port and if port has changed state, record time
int x=digitalRead(PORT);
if(n<BUF_SIZE && x!=prevx){
timespec_get(&rec[n++],TIME_UTC);
prevx=x;
}
}
int main(int argc, char **argv){
//initialize
wiringPiSetup();
wiringPiISR(PORT,INT_EDGE_BOTH,&ISR);
//give some time to receive message
delay(5000);
//print bit# and duration in microseconds
for(int m=1;m<n;m++){
long t = (rec[m].tv_sec-rec[m-1].tv_sec)*1000000+(rec[m].tv_nsec-rec[m-1].tv_nsec)/1000;
printf("%d:\t%d\n",m,t);
}
//print total nmber of bits and calls
printf("number of bits: %d, number of calls:%d\n",n,tot);
return 0;
}