2015-07-27 05:08 AM
Hello there,
I am trying to configure the acceptance mask of the CAN peripheral but I just cant seem to understand how does it work...CAN_FilterConfTypeDef sFilterConfig;
sFilterConfig.FilterNumber = 0; sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig.FilterIdHigh = 0x0000; sFilterConfig.FilterIdLow = 0x0000; sFilterConfig.FilterMaskIdHigh = 0x0000; sFilterConfig.FilterMaskIdLow = 0x0000; sFilterConfig.FilterFIFOAssignment = 0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 14; I need a 32 bit mask. I was trying to start filtering with not complicated filters like 0x01 or 0xFF that I have typed inFilterMaskIdLow
but the filter doesnt work. When 0x01 is written, it accepts everything and when 0xFF is written it doesnt accept can messages with ID 0xFF. Could someone please explain me how to use this filter? I though its like this: 32 bit filter = (FilterMaskIdHigh
<< 16) |FilterMaskIdLow
But its not. #can #filter2015-07-27 05:39 AM
My understanding is the High Order bits, of the High Order register are the Message ID
The Mask is a bit level mask (AND), ID compared (CMP) if ((MSBFirst32 & Mask) == ID) then Take; Assume the bits on the CAN bus are taken MSB first.2015-07-27 05:44 AM
For a STDID of 0x123
sFilterConfig.FilterIdHigh = 0x123 << 5; // High 11-bits sFilterConfig.FilterIdLow = 0x0000; sFilterConfig.FilterMaskIdHigh = 0xFFE0; // High 11-bits sFilterConfig.FilterMaskIdLow = 0x0000;2015-07-27 09:15 AM
Hello, thank you for answer. I have a 32 bit ID. So lets say I would like to receive all messages that contains 0xFF00 in it. How would the mask look? Do I then need to write anything to ID registers or keep them 0?
So i need the mask to be XXXXFFXX in hex, where X stands for dont care. How to understand these regs?2015-07-27 09:29 AM
The bit mask would look like whatever bits you want to drop through to the comparator below.
And however the 32-bit ID maps into the 11-bits of STID and 18-bits of EXID (29 bits by my math)2015-07-27 09:39 AM
You're doing a comparison, if you set the ID to zero, only messages that come to ZERO will match. Otherwise you need it to MATCH (or portion thereof) the ID you're looking for.
uint32 STID = 0x123; // Some nonsensical values for explicit pattern match, pick something relevent
uint32 EXID = 0x34567;
sFilterConfig.FilterIdHigh = (uint16_t)(((STID <<
5
) & 0xFFE0) | ((EXID >> 13) & 0x001F));
sFilterConfig.FilterIdLow = (uint16_t)(((EXID << 3) & 0xFFF8));
sFilterConfig.FilterMaskIdHigh = 0xFFE0 | 0x001F; // STID[10:0] and EXID[17:13]
sFilterConfig.FilterMaskIdLow = 0xFFF8; // EXID[12:0]
2015-07-27 09:56 AM
I think I finally understand, thank you. I dont have the board on me to test this, so i will do this tommorow morning and let know here.
2015-07-27 11:23 PM
Yes, I have managed to get it working now. Thank you again.