Skip to main content
MG.5
Associate II
December 14, 2020
Solved

Using both CAN1 & CAN2 both in STM32F446RC

  • December 14, 2020
  • 10 replies
  • 6367 views

Hi, I want to use both CAN1 and CAN2 for my application with 500kbps and 125kbps speeds respectively. I have initialized both of them as per my requirements using HAL. Where in Tx is implemented in polling and Rx in interrupts. CAN1 Tx and Rx working perfect. Coming to CAN2 Tx is working and Rx is not working. Interrupt itself is not firing up for CAN2 Rx (HAL_CAN_RxFifo0MsgPendingCallback is not being called). I've read in datasheet that some SRAM sharing process is happening between 2 CANs. I'm unable to comprehend that. Is that an issue?

I'm attaching the code also. Please check and help!

This topic has been closed for replies.
Best answer by Tesla DeLorean

Clear local/auto variable for predictable behaviour

CAN_FilterTypeDef sFilterConfig= {0};

For CAN2

 sFilterConfig.FilterBank = 0; // NO!! 14 thru 27 for CAN2 FILTERS

..

 sFilterConfig.SlaveStartFilterBank = 14; // THIS IS THE RESOURCE SPLIT POINT, 28 BANKS, 14 FOR CAN1 14 FOR CAN2 IN 50/50 SPLIT OPTION

10 replies

Tesla DeLorean
Guru
December 14, 2020

There are about 1.5X full CAN controllers, they share a FIFO, and the split is configurable. The CAN2 needs to use the second half of the FIFO, above the split point you have configured.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MG.5
MG.5Author
Associate II
December 14, 2020

Hi @Community member​ 

I didn't get what you said. There are 2 Rx FIFOs.

Should I use RXFIFO0 for CAN1 and RXFIFO1 for CAN2?

(or)

CAN_RDL0R and CAN_RDH0R must be managed for both CAN1 and CAN2?

Can you tell me where have I configured (above the) split point in my code?

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 14, 2020

Clear local/auto variable for predictable behaviour

CAN_FilterTypeDef sFilterConfig= {0};

For CAN2

 sFilterConfig.FilterBank = 0; // NO!! 14 thru 27 for CAN2 FILTERS

..

 sFilterConfig.SlaveStartFilterBank = 14; // THIS IS THE RESOURCE SPLIT POINT, 28 BANKS, 14 FOR CAN1 14 FOR CAN2 IN 50/50 SPLIT OPTION

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Parvez Akhtar
Associate
June 2, 2023

I wanted to us CAN2 interface in my project. I started with example application ("CAN_Networking"). This example application works very well with CAN1 but when CAN2 is configured in this application it doesn't work at all. No transmission and no reception. I tried recommended solution from here too but it still didn't work.

I searched online for similar problem and I got many issues related to same. But I tried all the solution and nothing worked. Sharing links below

https://stackoverflow.com/questions/36311263/stm32f1xx-can2-receive-interrupt-not-being-called

https://stackoverflow.com/questions/65290032/using-both-can1-can2-both-in-stm32f446-properly

https://stackoverflow.com/questions/27315649/stm32f429-is-not-receiving-the-can-message

I am sure it has something to do with filter setting and driver being provided by STM team. But it seems they didn't test their example programs with CAN2. 

  1. Why these application doesn't enable CAN1 clock by default whereas it is compulsory to enable CAN1 clock even if you are using only CAN2. 
  2. Why their driver initializes register with CAN1 address in HAL_CAN_ConfigFilter() irrespective of which driver (CAN1 or CAN2) address is passed to this function.

Please help me if anybody have solution of this problem.

mƎALLEm
ST Technical Moderator
June 2, 2023

@Parvez Akhtar

If you want to use CAN2, you have to enable CAN1 clock even if it will be not used. CAN1 APB clock should be enabled since CAN1 instance is a master from peripheral integration point of view and it manages the filtering part. 

Regarding the filtering management between CAN1 and CAN2, I invite you to have a look at this thread:

https://community.st.com/s/question/0D73W000000bHEESA2/detail?fromEmail=1&s1oid=00Db0000000YtG6&s1nid=0DB0X000000DYbd&s1uid=0050X000007vx9R&s1ext=0&emkind=chatterCommentNotification&emtm=1685418050174

Hope it helps.

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