2025-01-03 02:25 AM - last edited on 2025-01-03 02:53 AM by SofLit
Hi
I am using STM32F407 evb in which I have configured both CAN1 and CAN2 ,I am sendind CAN1(3 ids 501,502,503) and vice versa from CAN2 same I am sending but I am ble to recive all three id on CAN2 Rx but only one ID iam receving on CAN1(501) .I am sahring my filter configuration I am using mask mode
if (can_controller==0){
for (int i=0; i <CAN_MAXTABLEID_0; i++)
{
Can_Configfilter[i].FilterIdHigh = (0x501 << 5);
Can_Configfilter[i].FilterMaskIdHigh =(0xFFC << 5);
Can_Configfilter[i].FilterIdLow = 0x00000000; // Initialize if EXTID used
Can_Configfilter[i].FilterMaskIdLow = 0x00000000; // Initialize if EXTID used
Can_Configfilter[i].FilterFIFOAssignment = CAN_FILTER_FIFO_0;
Can_Configfilter[i].FilterBank = i; //Selection of filterBANk
Can_Configfilter[i].FilterMode = CAN_FILTERMODE_IDMASK; // Identifier mode
Can_Configfilter[i].FilterScale = CAN_FILTERSCALE_32BIT; // Scale selection
Can_Configfilter[i].FilterActivation = CAN_FILTER_ENABLE;// Example activation
Can_Configfilter[i].SlaveStartFilterBank=1; //0-2 CAN1 filter
Can_IPW_Can_ConfigFilter(&hcan,&Can_Configfilter[i]); //Filter configuration
}
}
if (can_controller==1){
for (int i=1; i <CAN2_MAXTFILTER; i++)
{
Can_Configfilter[i].FilterIdHigh = (0x501 << 5);
Can_Configfilter[i].FilterMaskIdHigh =( 0xFFC << 5);
Can_Configfilter[i].FilterIdLow = 0x00000000; // Initialize if EXTID used
Can_Configfilter[i].FilterMaskIdLow = 0x00000000; // Initialize if EXTID used
Can_Configfilter[i].FilterFIFOAssignment = CAN_FILTER_FIFO_0;
Can_Configfilter[i].FilterBank = i; //Selection of filterBANk
Can_Configfilter[i].FilterMode = CAN_FILTERMODE_IDMASK; // Identifier mode
Can_Configfilter[i].FilterScale = CAN_FILTERSCALE_32BIT; // Scale selection
Can_Configfilter[i].FilterActivation = CAN_FILTER_ENABLE;// Example activation
Can_Configfilter[i].SlaveStartFilterBank=1; //2-28 CAN2 filter
Can_IPW_Can_ConfigFilter(&hcan,&Can_Configfilter[i]); //Filter configuration
}
}
2025-01-03 02:51 AM
Hello,
For "controller 1" (I think CAN1). Here i starts from 0:
for (int i=0; i <CAN_MAXTABLEID_0; i++)
For "controller 2" (I think CAN2). Here i starts from 1:
for (int i=1; i <CAN2_MAXTFILTER; i++)
So what are the values of CAN_MAXTABLEID_0 and CAN2_MAXTFILTER?
I suspect an overlap of Filter config between CAN1 and CAN2! -> CAN_MAXTABLEID_0 should not exceed 1
2025-01-03 03:03 AM
hi
value as follows
CAN_MAXTABLEID_0 =1, and CAN2_MAXTFILTER=2
1. I Think filter configuration is fine .
First I am sending 3 id from CAN1 then 3 id From CAN2 in this case CAn2 is receving all three but CAn1 only one id.
2.than I interchange sending way this time I sent CAN2 first and CAN1 after ,in this case CAN2 receving only one and CAN1 receving all three IDs,
I am sending in 10 ms function.
2025-01-03 03:07 AM
For the moment use "pass all" IDs filters for CAN1:
Can_Configfilter[i].FilterIdHigh = 0x0000;
Can_Configfilter[i].FilterMaskIdHigh = 0x0000;
Can_Configfilter[i].FilterIdLow = 0x0000;
Can_Configfilter[i].FilterMaskIdLow = 0x0000;
And see if you get all the messages intended to be received.
2025-01-03 03:22 AM - edited 2025-01-03 03:26 AM
Hi
I have tried as u said still CAN1 only one ID I am receiving even CAN1 tx buffer and CAn2 tx buffer value is filled with correct DATA. in my CAN1 inside RF0R -> FMP value is only going upto one . and in CAN2 FMP value is getting upto 3.
NOTE: with the same I used to transmit from CAN2 to CAN1 it is working fine but when I m using both CAN1 and CAN2 at one time I am facing issue.
2025-01-03 03:59 AM
Also you used the same handle for both controller "hcan" to set the filters:
Can_IPW_Can_ConfigFilter(&hcan,&Can_Configfilter[i]);
Also Can_IPW_Can_ConfigFilter() is not part of HAL. It's your implementation. Also I don't see why you repeat the same filter config for CAN2 (two iterations for the same config!).
So at this stage, I suggest you to go step by step and start by using a very simple example:
if (can_controller==0)
{
sFilterConfig.FilterBank = 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 = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig)
}
if (can_controller==1)
{
sFilterConfig.FilterBank = 1;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig)
}
Here CAN1 and CAN2 are separated. If this works please add your Mask id config and try .. and so on.
2025-01-03 04:08 AM - edited 2025-01-03 04:13 AM
hi
Yes this is my code Hcan I am just using to check the state only nothing else.
apart from this one more query i wanted to run only can2Tx and CAn1 RX so I am sending 6 ID from CAN2 even I disable fifolocked but I am able to recive only 3 id .other three I am not reciving . CAN1 filter I configured for 0x0000 and MAsk too.
whatever three id I am sending first only those id I am ble to recivie so Why I am lossing other ID?anyIDEA
2025-01-03 04:12 AM
As said previously, I suggest to go step by step and start by using simple examples and debug.
2025-01-03 04:30 AM
Hi
I have tried the same still CAN1 RX(one id) issue CAN2 is fine(all three ID)
if (can_controller==0){
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterBank = 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 = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
Can_IPW_Can_ConfigFilter(&hcan, &sFilterConfig);
}
if (can_controller==1){
CAN_FilterTypeDef sFilterConfig1;
sFilterConfig1.FilterBank = 1;
sFilterConfig1.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig1.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig1.FilterIdHigh = 0x0000;
sFilterConfig1.FilterIdLow = 0x0000;
sFilterConfig1.FilterMaskIdHigh = 0x0000;
sFilterConfig1.FilterMaskIdLow = 0x0000;
sFilterConfig1.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig1.FilterActivation = ENABLE;
sFilterConfig1.SlaveStartFilterBank = 1;
Can_IPW_Can_ConfigFilter(&hcan, &sFilterConfig1);
st
2025-01-03 04:44 AM - edited 2025-01-03 04:53 AM
This is not the code I shared to test from your side:
@Ash1 wrote:if (can_controller==0){ CAN_FilterTypeDef sFilterConfig; sFilterConfig.FilterBank = 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 = CAN_RX_FIFO0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.SlaveStartFilterBank = 1; Can_IPW_Can_ConfigFilter(&hcan, &sFilterConfig); } if (can_controller==1){ CAN_FilterTypeDef sFilterConfig1; sFilterConfig1.FilterBank = 1; sFilterConfig1.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig1.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig1.FilterIdHigh = 0x0000; sFilterConfig1.FilterIdLow = 0x0000; sFilterConfig1.FilterMaskIdHigh = 0x0000; sFilterConfig1.FilterMaskIdLow = 0x0000; sFilterConfig1.FilterFIFOAssignment = CAN_RX_FIFO0; sFilterConfig1.FilterActivation = ENABLE; sFilterConfig1.SlaveStartFilterBank = 1; Can_IPW_Can_ConfigFilter(&hcan, &sFilterConfig1);
Please use the code I shared above. As I said Can_IPW_Can_ConfigFilter() is not part of the HAL and it's your implementation and hcan handle usage still ambiguous. So at this stage please use HAL_CAN_ConfigFilter() instead:
if (can_controller==0)
{
sFilterConfig.FilterBank = 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 = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig)
}
if (can_controller==1)
{
sFilterConfig.FilterBank = 1;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig)
}