2024-05-21 09:38 AM
Alright, I got my CAN stuff working in ID/mask mode, with 'all accepted' values.
I need to setup a CAN filter to only receive STD ID of 1512 (0x5e8).
I'm confused why this doesn't work. Using SPL looking at the CAN examples. I saw IDList, and this seemed appropriate because I only need 1 ID. But, after setting to IDList, and entering 0x5e8, it doesn't work.
/* CAN filter init */
CAN_FilterNumber = CAN_FilterNumber_0;
CAN_FilterActivation = ENABLE;
CAN_FilterMode = CAN_FilterMode_IdList;
CAN_FilterScale = CAN_FilterScale_16Bit;
CAN_FilterID1=0x5e8;
CAN_FilterID2=0;
CAN_FilterID3=0;
CAN_FilterID4=0;
CAN_FilterIDMask1=0;
CAN_FilterIDMask2=0;
CAN_FilterIDMask3=0;
CAN_FilterIDMask4=0;
CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode,
CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3,
CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2,
CAN_FilterIDMask3, CAN_FilterIDMask4);
I've seen mention of needing to include other bits, but I don't fully understand. If it's an ID list, why would any bits other than the ID need to be included?
2024-05-22 04:39 PM
Trying to think about it in binary....
0x5e8 - 010111101000
Appending RTR of 0, IDE of 0 to the end.
0x17a0 - 01011110100000
Now, in IdMask mode, this appears to work:
/* CAN filter init */
CAN_FilterNumber = CAN_FilterNumber_0;
CAN_FilterActivation = ENABLE;
CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterScale = CAN_FilterScale_16Bit;
CAN_FilterID1=0x17a0;
CAN_FilterID2=0;
CAN_FilterID3=0;
CAN_FilterID4=0;
CAN_FilterIDMask1=0x1FF0;
CAN_FilterIDMask2=0;
CAN_FilterIDMask3=0;
CAN_FilterIDMask4=0;
CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode,
CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3,
CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2,
CAN_FilterIDMask3, CAN_FilterIDMask4);
But, if I put it in IdList mode, with 0x17a0 as the only FilterID in the first spot, it doesn't work....
Why? I could achieve 0x17a0 by bit shifting to the left 2 bits, right?
But, overall, why doesn't this seem to work in IdList mode? (With the 0x1FF0 mask removed)