Skip to main content
bhargava
Associate II
July 14, 2015
Question

STM32 CAN networking demo - filter to accept everything?

  • July 14, 2015
  • 3 replies
  • 1350 views
Posted on July 14, 2015 at 23:53

Is the filter for the CAN ''Networking'' demo configured to accept all CAN frames?

#stm32 #can #example #code
This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
July 14, 2015
Posted on July 15, 2015 at 00:16

Yes

CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;

if ((X & 0) == 0) // Always Taken
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
bhargava
bhargavaAuthor
Associate II
July 15, 2015
Posted on July 15, 2015 at 18:25

Thanks again, clive. Mind explaining how the filter works? I can't find much about the specifics online.

Tesla DeLorean
Guru
July 15, 2015
Posted on July 15, 2015 at 19:12

I don't use CAN much, there's a lot of confusing examples on the internet, and a bunch can't possibly be right.

My inferred understanding is that the message ID is the top 11-bits of the filter. If I wanted one specific message I think this is the way to do it

/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = (ID << 5); // ID 11-bit in top bits
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFE0;// ID 11-bit in top bits, mask for comparison
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
// if ((bitstream & CAN_FilterMaskId) == CAN_FilterId)

To be less selective you'd open up the mask, and mask the id too. If you have a bus with an interesting selection of messages, shouldn't be more that a 10 minute task to nail this down. A 16-bit mode should permit id/mask to appear in both High and Low fields.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..