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
}
}
Solved! Go to Solution.
2025-01-03 05:13 AM
Hi
I have even tried with HAL as u said still same issue .
can you explain if my filter configuration is wrong why it is recving CAN2 rx (all ID) .this is I am unable to understand.
2025-01-03 05:29 AM
Could you please share you project with the exact code you used in the latest test? I mean with the simple example I've shared previously.
2025-01-03 06:33 AM - edited 2025-01-03 09:22 AM
I've created a simple project where CAN1 and CAN2 are in loopback mode using STM32F407 Discovery board and I'm receiving well all the sent IDs: 0x502 (1281), 0x502 (1282), 0x503 (1283) on both sides CAN1 and CAN2:
CAN1 Rx:
CAN2 Rx:
I've attached the project.
I've also used that configuration and worked fine:
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = (0x501 << 5);
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = (0xFFC << 5);
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
if(HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
sFilterConfig.FilterBank = 1;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = (0x501 << 5);
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = (0xFFC << 5);
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 1;
if(HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
So I suspect something wrong in your specific implementation, either in your Can_IPW_Can_ConfigFilter() or with the handler hcan that was not set correctly in your software.
Hope it helps.
2025-01-03 08:04 PM - edited 2025-01-04 02:30 AM
Hi
Can you attached your project so that I can too test on my board.
I am running both can on 500kbps so will it be baudrate issue or not ?
Doubt1: I have attached same code that you have tested I have one doubt you have added delay(10ms) in between HAL_CAN_ADDTXmessage. what if there is no 10ms delay in between HAL_CAN_ADDTXmessage I mean to say CAn you try with delay at the end of both .will it work the same? Like I want to transmit both CAN1TX and CAN2TX in very 10ms delay
what is the purpose of adding delay in between HAL_CAN_ADDTXmessage.
I have attached modified code CAN you test that too.
Doubt2:: If I try to send 6 ID in single delay (10ms) without any delay between HAL_CAN_ADDTXmessage from CAN1 to CAN2 will all id will transmit or only first three I will receive on CAN2RX
{
CAN1_TxHeader.StdId = CAN1_Tx_ID_List[i];
CAN1_TxData[0] ++;
CAN1_TxData[1] --;
if (HAL_CAN_AddTxMessage(&hcan1, &CAN1_TxHeader, CAN1_TxData, &CAN1_TxMailbox) != HAL_OK)
{
/* Transmission request Error */
Error_Handler();
}
CAN2_TxHeader.StdId = CAN2_Tx_ID_List[i];
if (HAL_CAN_AddTxMessage(&hcan2, &CAN2_TxHeader, CAN2_TxData, &CAN2_TxMailbox) != HAL_OK)
{
/* Transmission request Error */
Error_Handler();
}
HAL_Delay(10);
i++;
if (i == 3) i = 0;
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
2025-01-06 12:50 AM
@Ash1 wrote:
Hi
Can you attached your project so that I can too test on my board.
It's already attached:
But this is tested on STM32F4Discovery board. You need to adapt it on your board, mainly the clocks and the CAN GPIOs.
If you don't insert that delay you risk to get a non-empty Tx mailbox. Note that you have only 3 mailboxes on transmit and if you keep calling HAL_CAN_AddTxMessage() and the CAN has no enough time to drain the messages you send for a given reason (arbitration reason for example), you will risk to loose messages.
2025-01-06 01:29 AM
hi
Same thing I am facing I am only able to see first three messages .as other three mesages not updating on buffer as tx mailbox is not empty. so how much time does it take mailbox get empty any idea ?
2025-01-06 01:35 AM - edited 2025-01-06 02:05 AM
Hello,
"how much time does it take mailbox get empty any idea ?" There is no timing available for this. It depends mainly on the bus load and the priorities of the message you send.
Did you test my project I shared? what did you find? did you get all the massages? need to avoid useless Ping-Pongs. So please confirm if the project I shared is working for you.
Thank you.
2025-01-06 01:44 AM
Hi
project is working fine.
2025-01-06 01:49 AM
and if you remove the delay in the project I shared what happens?
2025-01-06 03:12 AM
Hi
yes because I am trying to send 6 continously ID with single delay at end .
I got your point thanks