cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 CAN filter doesn't work

OMarc.1
Associate III

Hi everyone.

I have next problem. I trying to use CAN filter option, sometimes i need to configure them on fly. First basic filter its standard filter:

/*CAN*/

canfil.FilterBank = 0;

canfil.FilterMode = CAN_FILTERMODE_IDMASK;

canfil.FilterFIFOAssignment = CAN_RX_FIFO0;

canfil.FilterIdHigh = 0x0000;

canfil.FilterIdLow = 0x0000;

canfil.FilterMaskIdHigh = 0x0000;

canfil.FilterMaskIdLow = 0x0000;

canfil.FilterScale = CAN_FILTERSCALE_32BIT;

canfil.FilterActivation = ENABLE;

canfil.SlaveStartFilterBank = 14;

HAL_CAN_ConfigFilter(&hcan1,&canfil);

HAL_CAN_Start(&hcan1);

HAL_CAN_ActivateNotification(&hcan1,CAN_IT_RX_FIFO0_MSG_PENDING);

When i need to change filter only for one address 0x18 FEDA02

canfil.FilterBank = 0;

canfil.FilterMode = CAN_FILTERMODE_IDMASK;

canfil.FilterFIFOAssignment = CAN_RX_FIFO0;

canfil.FilterIdHigh = (uint16_t)(0x18FEDA02>>13);;

canfil.FilterIdLow = (uint16_t)(0x18FEDA02<<3) | 0x04;;

canfil.FilterMaskIdHigh = (uint16_t)(0x1fffffff>>13);

canfil.FilterMaskIdLow = (uint16_t)(0x1fffffff<<3) | 0x04;

canfil.FilterScale = CAN_FILTERSCALE_32BIT;

canfil.FilterActivation = ENABLE;

HAL_CAN_ConfigFilter(&hcan1,&canfil);

HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, canRX );

And i see many different adreses, not only 0x18FEDA02. Maybee i need to add something. 

And we have option to add another number of filter, how we can chouse what number of filter should do at this moment?

Thank you, for your reply.

Kind regards,

Oleksii 

3 REPLIES 3
Javier1
Principal

after reading your question i still dont know what is happening.

Are both filters working by themselves? or is the "on the fly" change what is giving you trouble?

we dont need to firmware by ourselves, lets talk
OMarc.1
Associate III

For example, i want only 0x18FEDA02, but when i write data from frame, i see another adresses like 18FFCC100 and other. I can't undestand how to chouse what filter should working at this time.

Could i change in code to reconfigure filter 0 to another data, when it was started before?

Or i need add another filter for example 1. How to select filter 1?

Because if filter 0 working with all adresses like that:

canfil.FilterBank = 0;

canfil.FilterMode = CAN_FILTERMODE_IDMASK;

canfil.FilterFIFOAssignment = CAN_RX_FIFO0;

canfil.FilterIdHigh = 0x0000;

canfil.FilterIdLow = 0x0000;

canfil.FilterMaskIdHigh = 0x0000;

canfil.FilterMaskIdLow = 0x0000;

canfil.FilterScale = CAN_FILTERSCALE_32BIT;

canfil.FilterActivation = ENABLE;

canfil.SlaveStartFilterBank = 14;

What's the point of adding other filters if they work at the same time.

The null filter will always let information through.

Please understand, I am using the CAN bus for the first time, in STM32 and I may not know something.

Because i can't see filter option in command

HAL_CAN_GetRxMessage(hcan, RxFifo, pHeader, aData)

Thank you.

For example, i want only 0x18FEDA02, but when i write data from frame, i see another adresses like 18FFCC100 and other. I can't undestand how to chouse what filter should working at this time.

Could i change in code to reconfigure filter 0 to another data, when it was started before?

Or i need add another filter for example 1. How to select filter 1?

Because if filter 0 working with all adresses like that:

canfil.FilterBank = 0;

canfil.FilterMode = CAN_FILTERMODE_IDMASK;

canfil.FilterFIFOAssignment = CAN_RX_FIFO0;

canfil.FilterIdHigh = 0x0000;

canfil.FilterIdLow = 0x0000;

canfil.FilterMaskIdHigh = 0x0000;

canfil.FilterMaskIdLow = 0x0000;

canfil.FilterScale = CAN_FILTERSCALE_32BIT;

canfil.FilterActivation = ENABLE;

canfil.SlaveStartFilterBank = 14;

What's the point of adding other filters if they work at the same time.

The null filter will always let information through.

Please understand, I am using the CAN bus for the first time, in STM32 and I may not know something.

Because i can't see filter option in command

HAL_CAN_GetRxMessage(hcan, RxFifo, pHeader, aData)

Thank you.