I know this thread is a little old, but for future readers: It really depends on your use case.
An important thing to consider is bus loading and ignored packet frequency. If your bus is near capacity and most packets aren't relevant to your device you might spend more cycles than you want ignoring packets.
When to hardware filter:
If useful/actionable data will NEVER come from the filter mask and you want to avoid using CPU time to filter.
Example:
If you're building a Tachometer, it probably never needs to process data from the Air Conditioner. A hardware filter will save you CPU cycles and inconvenient interrupts.
When to code a filter:
During testing/beta when you aren't 100% sure what data you may need.
In an environment that changes frequently.
If your filter changes based on program flow control.
Example:
If you built a CAN bootloader you'd want to ignore bootloader commands that aren't for you. Once you go into bootloader "mode" you could use a flag to process bootloader commands.
Can Bootloader Filter
if(msg.id == 0x01 && BootloaderModeEnabled )
{
// Your Bootloader Code
}
This will still cost you CPU cycles for every CAN packet, but you won't need to bother processing some of them under some circumstances.
Hi,
With reference to CAN bus example code in http://mbed.org/handbook/CAN, I am trying to modify the code in order to receive a message with specific ID.
The follwoing read CAN function: "can1.read(msg)" receives any message, and I want to specify the message ID that it can receive.
Any advise?
Thanks in advance