2018-09-28 02:42 AM
I set on a slave
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0064;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x00FF;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
master sends
TxMessage.ExtId = (opcode << 8) | 0х64;
but the slave dosen't get the message. without mask and filter the slave gets the message.
how should I set the mask and filter?
2018-10-20 10:48 PM
any body? no one in the community knows how the CAN filter works in STM32?
2018-10-21 02:55 AM
here you can see some bits are high in the mask ? only these bits are tested in the filter
//##-2- Configure the CAN1 Filter ###########################################
sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x400 << 5; //11-bit ID in top bits
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x600 << 5; // resolves as 0x0400 - 0x05FF
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 0;
The Mask is 0x600 // only these two bits are tested
The Filter is 0x400 // in those two bits, A9 must be high and A10 must be low,
everything else is "dont care", we only care about the Masked bits.
so anything within 0x400- 0x5FF is accepted
2018-10-21 03:41 AM
I see. Thank you.
But in my case - if I want to accept the messages only for ID = 0xXX64 (XX - don't care) - my settings above seems to be valid. However I don't get any messages with the filter applied.
2018-10-21 05:44 AM
can you see my mask bits are shifted up 5 bits ?
sFilterConfig.FilterIdHigh = 0x400 << 5; //11-bit ID in top bits
2018-10-21 06:19 AM
Ah... I see. The mask should be shifted. Thank you.
2018-10-21 06:59 AM
I just can't understand - why shift 5? It should be 3.
Ah...I see. STDID is in High part of the register.
2018-10-21 08:04 AM
Depends on what you're matching, the top half of the diagram is the High and the bottom is the Low portion.
For the STDID you want to use the high filter with the pattern shifted left 5 bits.
Filters have been described on the forum multiple times over close to a decade.
2018-11-04 12:15 AM
Still can't get it working.
I want to get ID = 0x64 , the rest don't care
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0064 << 5;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x00FF << 5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
But when a master sends ID = 0x1164 I don't get it with the filter applied.
2018-11-04 01:01 PM
is that an extended ID ? or std ID ?
is that address outside the address range ? 0x1164 << 5 overruns the 16bit value...
if you are using extended IDs, then <<3 is correct...