I'm using digitalRead of wiringPi to detect packet received in CAN chip, so i'm send data and wait for falling edge of the can interrupt pin as you can see here:
gettimeofday(&t1, NULL);
digitalWrite(7,HIGH);
do{
delayMicroseconds(10);
if(!digitalRead(CAN_INT_PIN)){
//if(waitForInterrupt(CAN_INT_PIN,-1)){
//Dados novos no buffer, resta saber qual
events = DRV_MCP25625_ModuleEventGet();
if (events & DRV_MCP25625_RXB1_EVENT) {
DRV_MCP25625_ReceiveMessageGet(DRV_MCP25625_RX_CH0, &rxObj, rxd, 8);
pcBuf[0] = 'M';
pcBuf[1] = rxObj.ctrl.DLC; //Data length
pcBuf[2] = rxObj.id.SID & 0xFF;
pcBuf[3] = (unsigned char) rxObj.id.SID>>8;
memcpy(&pcBuf[4],rxd,8);
// Clear flag
DRV_MCP25625_ModuleEventClear(DRV_MCP25625_RXB1_EVENT);
digitalWrite(7,LOW);
return 12;
}
// Check RXB0
if (events & DRV_MCP25625_RXB0_EVENT) {
// Get message
DRV_MCP25625_ReceiveMessageGet(DRV_MCP25625_RX_CH0, &rxObj, rxd, 8);
pcBuf[0] = 'M';
pcBuf[1] = rxObj.ctrl.DLC; //Data length
pcBuf[2] = rxObj.id.SID & 0xFF;
pcBuf[3] = (unsigned char) rxObj.id.SID>>8;
memcpy(&pcBuf[4],rxd,8);
// Clear flag
DRV_MCP25625_ModuleEventClear(DRV_MCP25625_RXB0_EVENT);
digitalWrite(7,LOW);
return 12;
}
}
gettimeofday(&t2, NULL);
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
//elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
//printf("Elapsed Time: %.2f\n",elapsedTime);
}while(elapsedTime <= *iTimeout );
digitalWrite(7,LOW);
The problem is that sometimes raspberry don't detect falling edge of the pin. In this image is working: https://ibin.co/3M6fO9qtumjH.png
Here you can see that in channel 5 we have the interrupt in every packet received and after i get the packet over spi. At 1s260ms i send a packet over spi and CAN again, and wait... In next image you can see that i have the falling edge in channel 5 and the raspberry don't detects.. https://ibin.co/3M6hqWJzPMHA.png
Thanks