CAN-BUS - how do I filter stuff ?

hi.

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 ?

regards
Elo

I asked this months ago but never got an answer. The library didn’t work with 29bit canid’s either.

thank you for your reply.

That’s sad.

I guess I have to skip this product then.

As an alternative I am considering directly wiring my cheap elm327 clone bought off ebay china (OBD2-USB device) to my arduino board.

I just thought this shield would save me some work.
hehe

regards
Elo

There are other libraries out there, the shield itself works fine.

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.

I ended up using this one, although with software filtering.

modelrail.otenko.com/arduino/ard … etwork-can

Thank you I will take a look, I thought the bus may be too busy so I attached to the AV Bus (much less traffic) and still get the same problem.

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.

I’ve swapped to ChipKit MAX32 with network shield, dual can-buses and a library written by Microchip.

Filtering works spot on.

That there actually looks pretty nifty… While you’ve moved on, I have found that filtering with this library works as expected.

To enable receiving everything without commenting out a section in the library, add the below after ‘CAN.begin();’ in the sketch…

CAN.init_Mask(0,1,0x00000000);
CAN.init_Filt(0,0,0x00000000);
CAN.init_Filt(1,1,0x00000000);

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.