I am still in the process of contemplating buying the seeedstudio CAN bus shield.
Essentially I want to make sure that I am able to listen for a very specific can bus message in my car.
The car’s onboard climate control computer sends a request on the CAN bus when ever A/C compressor activiation is requested.
It is this message I want to intercept.
I did successfully identify the message using a cheap OBD2-USB adapter (elm327) along with hyperterminal for windows.
so I used the following AT commands for init:
ATL1
ATH1
ATS1
ATAL
ATSP6 (ISO 15765-4 CAN (11 bit ID, 500 kbaud))
and the filter command itself:
ATCRA374
issuing a ATMA command then gives me the following hex values:
AC Request ON MSG: 374 XX 32 YY (32 = AC on)
AC Request OFF MSG: 374 XX 22 YY (22= AC off)
note: XX and YY indicates bytes that I dont care about.
as you have guessed I want to exactly filter out messages where I want to :
listen for transmitter with id = 374
listen for incoming bytes that match the value “32” at position 6.
how would I construct my init filter call for this example ?
I would be interested in any filtering examples, I’ve tried a couple of other libraries out there but no luck. Can you please point us at one that you know works?
Using the receive example I get a 3-4 messages before the serial monitor freezes and left with the INT led on and Rx flickering.
The library does support extended CAN frames, however I am still figuring out the library to its entity as I had to comment out a section in the library that sets certain bits so I can receive everything… I have already discovered a bug when trying to read extended frame IDs greater than 0x00007FFF. As for interrupts, the sample code that uses the Atmega’s interrupt handling doesn’t work the way the MCP2515 uses its /INT line. I discovered that the MCP2515 holds its /INT line low when the buffer is full, its not a one shot like the interrupt handler is expecting it to be. In essence, the /INT line remains low, the flag never gets set again because the interrupt handler never sees a falling edge, and the Arduino loops waiting for the flag to be set. Instead, I just monitor the pin and if it is low, I read the MCP2515. I’ve been able to monitor fast buses setup like this with no crashing. I’ve been working on this for about a week when I have the time… this was the first library for the MCP2515 I was able to get working. Out of the box, you should be able to receive standard frames.
Setting all of the mask bits to 0 causes it to pass through the filter regardless of its setting… HOWEVER, there is a bit in the filter that sets EXCLUSIVELY whether or not to accept extended frames. The second value in the above functions sets that bit. That code sets up the first receive buffer mask to allow anything, then sets up the first filter to exclusively to allow all standard frames and finally sets the second filter to exclusively allow all extended frames.
Ideally, if you want to receive a specific frame ID, set the all mask bits to 1 and define the filter(s) for the specific ID(s) you are wanting.
That makes sense thanks. We should be able to accept both on each filter, anyway, PIC is my future!
I figured out that much but never got the filtering to work for a CANID, but I think I made a mistake with the MSB on the network I was using…
FWIW, the Microchip library is complete, but it needs a bit of work to wrap up the functions depending on each requirement, type of CAN network etc, I guess most of the non-std stuff would be like that anyway.
That is actually incorrect according to page 34 of the MCP2515 data sheet, RXFnSIDL bit 3 only allows one, or the other. Two filters need set to receive extended and standard frames if RXBnCTRL (page 27) bits 6 and 5 are set to ‘00.’ If those bits are set to ‘11’ then the MCP2515 ignores the masks and filters altogether. The section I commented out in the library to get the chip to receive everything was setting RXBnCTRL bits 6 and 5 to ‘00.’ Since figuring out the masks and filters, I’ve restored that section of my library.