I want to enter the interrupt when a CAN message is received by the MCP, process that CAN message and continue with my program. The function that is called by the interrupt is the following one:
The device has a receive buffer so you would normally use a 'level' rather than an 'edge' triggered interrupt.
This ensures you process all messages, not just the first in the buffer.
Alternatively include a check inside the interrupt to see if there are more messages to process after you have processed the first. The INT pin will only be reset once the buffer is fully empty.
Ok, I will try to change the interrupt to a level. This can be the problem because when I try my code, I only receive one message and the program don't enter the interrupt again. The INT pin I have to reset it manually or the library reset it automatically?
Yes, the code works outside the ISR. I don't know if I had to modify anything in the library because I don't know if the library reset by himself the INT pin.
The return of the value of my method works properly.
Dashboard_Arduino_ePR02_CAN_v2.ino (9,0 KB)
That's the full code, the final line that calls a function "CAN0.clearInterrupts()" is the function I modified in the .cpp of the library based in other libraries.
That code still uses an edge interrupt and your code doesn't check for multiple messages. If the 2515 still has messages in the queue you cannot reset the interrupt (according to the datasheet).
My interpretation of the datasheet is that you can still have the same code (try to reset it each after each message), it won't succeed before the last message was handled. Try it and tell us the result.
I finally get a result but with the library "arduino-mcp2515-master". Some month ago I was using this, but it doesn't work with the display I am configuring because of the CNF values but I change them and it works. I think that library works better than the other.