2020-09-21 03:44 PM
Hello everyone
I want to know if I can set the two can interface in slave and recieve messages ,I have could get message from one or another setting the index of filter ,but I need listen both at the same time :(.Any idea ? or is the any hw limitation?.And if there is a problem then I can select in "runtime" one interface and then the other , alternating.
Thanks !
2020-09-21 03:57 PM
Both CAN1 and CAN2 can operate concurrently, using the same filters in each, or not.
They will both need to be connected to the same bus to see the same traffic.
2020-09-21 04:13 PM
Uhm I've noticed that when I select CAN_FilterInitStructure.CAN_FilterNumber = 0; I get interrupts from can1 and can2 is blocked ,otherwise with 14 works can2 but not can1.PD: Using SPL .Also I need two separate can interface due I'm reading from a vehicle with two CAN diferent interfaces
2021-07-09 04:31 AM
Dear @Jvela.1 ,
You can use several CAN instances in parallel but I will try to explain how to assign filters for each CAN instance:
1- In case of single instance of CAN peripheral, 14 filter banks are available to filter CAN1 messages.
We can assign any filter to any FIFO. The received and accepted message will be available in one of the three receive mailbox of the FIFO that was assigned to the filter that accepted the message.
2- In case of DUAL instances of CAN peripheral (CAN1 and CAN2 which is your case), 28 filter banks are available to filter CAN messages. In that case Filters are shared between the two instances.
.SlaveStartFilterBank member in the filter structure in the Cube HAL driver defines the number of filters allocated to CAN1 and CAN2. It sets CAN2SB field in CAN_FMR register.
The value of CAN2SB can be seen as "a cursor" that configures the amount of filters allocated to CAN1 and CAN2.
- If CAN2SB (.SlaveStartFilterBank) = 14: 14 filters are allocated to CAN1 (Filters 0 to 13) and 14 filters are allocated to CAN2 (Filters 14 to 27).
- If CAN2SB (.SlaveStartFilterBank) = 28: all filters are allocated to CAN1. In that case CAN2 will be not used and you can't receive any message on CAN2.
- If CAN2SB (.SlaveStartFilterBank) = 0: all filters are allocated to CAN2. In that case CAN1 will be not used (and you can't receive any message on CAN1) but CAN1 APB clock should be enabled since it's a master (from implementation point of view) and it manages the filtering part.
Case 1:
CAN2SB = 14
(cursor set to 14)
|
|------CAN1 part------14-------CAN2 part-----|
0 27
\_____________________/\_____________________/
Filters allocated Filters allocated
to CAN1 to CAN2
Case 2:
CAN2SB = 0
(cursor set to 0)
|
|-------------------------------------------|
0 27
\___________________________________________/
All filters are allocated
to CAN2
Case 3:
CAN2SB = 28
(cursor set to 28)
|
|-------------------------------------------|
0 27
\___________________________________________/
All filters are allocated
to CAN1
Case 4:
CAN2SB = 9
(cursor set to 9)
|
|-CAN1 part--9-----------------CAN2 part-----|
0 27
\___________/\______________________________/
9 Filters 18 Filters allocated
allocated to CAN2
to CAN1
Regarding .FilterBank and .SlaveStartFilterBank parameters in the filter structure in the driver:
- For CAN1: .FilterBank should be always < .SlaveStartFilterBank.
- For CAN2: .FilterBank should be always >= .SlaveStartFilterBank.
3- For devices having three CAN instances. CAN1/CAN2 have the configuration of DUAL configuration. CAN3 is a master and it's independent from CAN1/CAN2 and it has its own filters.
Hope this clarifies how to assign filters for each CAN instance.
STM32
2021-07-09 04:34 AM
It seems that some parts of the text are not shown in a correct manner I attach a sceernshot:
STM32