cancel
Showing results for 
Search instead for 
Did you mean: 

how to use stm32f407 dual can communication(can1 & can2)

KHyun.1
Associate II

Hello.

I'm currently researching can communication with stm32f407vg

currently, i want to use can1 and can2 at the same time, but only one of them works.​

canfilter is used, and the test is currently in progress through timer interupt.​

maybe the can filter part is wrong, but i couldn't find the answer, so I want to ask for help.

thanks you for your help

0693W00000NqK9JQAV.png0693W00000NqK8gQAF.png0693W00000NqK9TQAV.png0693W00000NqK9UQAV.png

16 REPLIES 16

Thanks for the reply. There are two separate ADM3055E transceivers. One on each bus.

Hi, the hardware is ok. Both busses are transmitting valid CAN messages. Just that FDCAN2 is sending a wrong message which indicates that it is not using the correct buffer.

Nickelgrass
Senior

Sorry, please ignore my comments. I posted in the wrong thread! Have a similar one open in another tab and thought it was replies to that one. Can a moderator please delete my answers in this thread. Thanks.

Same. The master-slave filter bank. You can start any one of the CAN peripherals with any filter bank (0 or 1, etc.), it will work. The slave filter may start from anywhere, doesnt matter, it wont work. I dont understand why

@Kunaalkk1 

I’ve already answered your question in your thread here: https://community.st.com/t5/stm32-mcus-products/stm32f407-dual-can-first-can-instance-both-tx-rx-works-second/td-p/819950

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@KHyun.1 @mƎALLEm @Nickelgrass @Tesla DeLorean @Andrew Neil 

I know my solution sounds crazy, but I did find a solution to this problem. Every time before uploading/debugging the code, use the STM32Cube programmer/utility tool to fully erase the flash. It worked for me. Figured there must be some issue in HAL when rewriting the code during re-upload, so I erased the code itself. Works for me.

Here is my filter config snippet that doesn't filter any data out:

 

void can_init(void) {
    CAN_FilterTypeDef sFilterConfig1 = {
        .FilterBank = 0,
        .FilterMode = CAN_FILTERMODE_IDMASK,
        .FilterScale = CAN_FILTERSCALE_32BIT,
        .FilterIdHigh = 0x0000,
        .FilterIdLow = 0x0000,
        .FilterMaskIdHigh = 0x0000,
        .FilterMaskIdLow = 0x0000,
        .FilterFIFOAssignment = CAN_RX_FIFO0,
        .FilterActivation = ENABLE,
		.SlaveStartFilterBank = 14
    };

    HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig1);
    sFilterConfig1.FilterBank = 14;
    sFilterConfig1.FilterFIFOAssignment = CAN_RX_FIFO1;

    HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig1);
    HAL_CAN_Start(&hcan1);
    HAL_CAN_Start(&hcan2);

	// Activate notifications for both CAN interfaces
	if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
		Error_Handler();
	}

	if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK) {
		Error_Handler();
	}
}

 

Just ensure you erase full chip before uploading/debugging and it will work!

Sounds like you have something else stored in Flash that's causing the problem.

 


@Kunaalkk1 wrote:

@KHyun.1 @mƎALLEm @Nickelgrass @Tesla DeLorean @Andrew Neil 


There's no need to tag everyone - people get notified of any reply in the thread

 


@Kunaalkk1 wrote:

Figured there must be some issue in HAL when rewriting the code during re-upload, !


No, that's not it.

HAL is not involved in code download - unless you've written a custom bootloader using it?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.