2016-01-19 04:53 PM
Hello!
I have configured my filter banks. However, the standard ID that the receive FIFO0 register is reading after controller transmits a response to my module is not what I expect. Hence, I suspect this phenomenon is due to incorrect message filtering that causes an incorrect bit sequence to be stored in the receive FIFO0 register. The following is my code:CAN_FilterConfTypeDef CAN_FilterConfig[5] = {
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 0, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = (0x7FF << 5), .FilterMaskIdHigh = 0,
.FilterIdLow = (STID1 << 5), .FilterIdHigh = 0},
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 1, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdHigh = (0x7FF << 5), .FilterMaskIdLow = 0,
.FilterIdHigh = (STID2 << 5), .FilterIdLow = 0},
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 2, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = (0x7FF << 5), .FilterMaskIdHigh = 0,
.FilterIdLow = (STID3 << 5), .FilterIdHigh = 0},
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 3, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdHigh = (0x7FF << 5), .FilterMaskIdLow = 0,
.FilterIdHigh = (STID4 << 5), .FilterIdLow = 0},
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 4, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdHigh = 0, .FilterMaskIdLow = (0x7FF << 5),
.FilterIdHigh = 0, .FilterIdLow = (STID5 << 5)},
};
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterConfig[0]);
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterConfig[1]);
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterConfig[2]);
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterConfig[3]);
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterConfig[4]);
I have configured 5 messages in the filters using filter numbers 0 to 4.
Is this configuration correct?
Is this what determines what is stored in the can receive FIFIO 0 (CAN_RIXR) register?
FYI, I am using a STM32F302 custom made board.
Thank you!
2016-01-19 08:34 PM
The basic problem here is one of not understanding 16-bit filters. You basically split the 32-bit comparator in two so that each entry represents two independent filters, one in the low word, and the other in the high word. By defining the high mask/match as zero you've created a test that passes everything.
ie ((X & 0) == 0), is always true, thus all cases pass As I understand it, you'd pack two filters in each entry like this{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 0, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = (0x7FF << 5), .FilterMaskIdHigh = (0x7FF << 5),
.FilterIdLow = (STID1 << 5), .FilterIdHigh = (STID2 << 5)},
2016-01-20 04:26 PM
Hi Clive,
Thanks a lot for your reply. I have amended my code to this:CAN_FilterConfTypeDef CAN_FilterConfig[3] = {
{.BankNumber = 0, .FilterActivation = ENABLE, .FilterNumber = 0, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = (0x7FF << 5), .FilterMaskIdHigh = (0x7FF << 5),
.FilterIdLow = (STID1 << 5), .FilterIdHigh = (STID2 << 5)},
{ .FilterActivation = ENABLE, .FilterNumber = 1, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_16BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = (0x7FF << 5), .FilterMaskIdHigh = (0x7FF << 5),
.FilterIdLow = (STID3 << 5), .FilterIdHigh = (STID4 << 5)},
{ .FilterActivation = ENABLE, .FilterNumber = 2, .FilterFIFOAssignment = 0,
.FilterScale = CAN_FILTERSCALE_32BIT, .FilterMode = CAN_FILTERMODE_IDMASK,
.FilterMaskIdLow = 0, .FilterMaskIdHigh = (0x7FF << 5),
.FilterIdLow = 0, .FilterIdHigh = (STID5 << 5)},
};
I am able to receive message properly for one type of message (ie STID3) but I expect to also receive STID2 message but I am not able to receive STID2 message.