CAN Messages and Filtering
Just prior to sending an OBD request, the ELM327
will make sure that the receive filters are set to only
accept certain types of messages, and to reject others.
With the older protocols (J1850, ISO 9141, etc.) the
filters only need to monitor a single byte (much like the
AT MR and MT commands), but with CAN protocols, a
decision typically requires looking at all of the ID bits.
The decision whether to receive a CAN message
or to ignore it is made by what is called an ‘acceptance
filter’. This filter works in conjunction with a ‘mask’,
which is actually a filter on the filter that says which
bits are relevant, and which ones can be ignored. A
few examples might be best to describe how to set the
filter and the mask.
By far the easiest way to set both the filter and the
mask is with the AT CRA command. You don’t really
need to know anything about filters and masks to use
it - simply send the command with the address that
you want to see, and the ELM327 does all the work for
you. For example, if the only messages that you wish
to see are those that have the CAN ID 7E9, then
simply send:
>AT CRA 7E9
and the ELM327 will set the necessary values so that
all that is displayed are messages with ID 7E9.
If you would like to see a range of values, rather
than a specific ID, then you will need to manually
define the filter and the mask. For example, consider
an application where you are trying to monitor for 29
bit CAN diagnostic messages, exactly like the ELM327
does. By definition, these messages will be sent to the
scan tool at address F1, so from ISO 15765-4, you
know that the ID portion of the reply is of the form:
18 DA F1 xx
where xx is the address of the ECU that is sending the
message. Clearly a filter is needed that requires the
first 21 bits to match, but does not care what the last
eight bits contain.
To create such a filter, we first use the CAN Filter
command to enter the ID values that correspond to the
values that you want to match, and put any value in for
the unknown portion (you will see why in a moment).
For this example, the command would be:
>AT CF 18 DA F1 00
Now, how do you tell the ELM327 to ignore those
41 of 76
ELM327DSH Elm Electronics – Circuits for the Hobbyist
www.elmelectronics.com
last two 0’s? You do that with the mask. The mask is a
bit pattern that tells the ELM327 which bits in the filter
are relevant. If the mask bit is 1, that filter bit is
relevant, and is required to match. If it is 0, then that
filter bit will be ignored. All bits in this filter are relevant,
except those of the last byte. To set the mask then,
you would need to use the CAN Mask command, and
put 1’s for all but the last byte:
>AT CM 1F FF FF 00
After setting the mask and filter in this way, only
IDs that start with 18 DA F1 will be accepted by the
ELM327, and all others will be ignored. Be careful
when experimenting with this, as you will override the
default settings, and you might stop ‘seeing’ any
replies to the requests.
The 11 bit CAN IDs are treated in much the same
manner. Recall that they are stored internally in the
right-most 11 bits of the locations used for 29 bit CAN,
which must be considered when creating a filter or
mask. As an example, assume that we wish to display
all messages that have a 6 as the first digit of the 11
bit ID. We need to set a filter to look for 6 in that digit:
>AT CF 00 00 06 00
The 11 bit ID is stored in the last three locations,
so the 6 would appear where it is shown. Now, to
make only that digit relevant, we create the mask:
>AT CM 00 00 0F 00
Technically, this one digit actually represents 3
bits of the 11 bit ID, so we should not use F (ie 1111)
for the mask, but the ELM327 will only look at the 11
bits, and does not care what we put in the 12th bit (so
we can be lazy).
Clearly, trying to insert 11 bits into the right spot in
a 29 bit ID can be quite cumbersome. To help with
that, the ELM327 offers some 11 bit versions of the CF
and CM commands, which can be used as follows for
the above commands:
>AT CF 600
OK
>AT CM F00
OK
Again, only the 11 least significant (right-most)
digits are actually used, and the ELM327 ignores the