cancel
Showing results for 
Search instead for 
Did you mean: 

Using both CAN1 & CAN2 both in STM32F446RC

MG.5
Associate II

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!

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

10 REPLIES 10

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
Up vote any posts that you find helpful, it shows what's working..

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?

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
Up vote any posts that you find helpful, it shows what's working..

One more update - I tried configuring FIFO0 for CAN1 and FIFO1 for CAN2.

Result - Now CAN2 is receiving data perfectly and CAN1 doesn't even call callback function.

What's wrong?

MG.5
Associate II

Hey @Community member​ 

As suggested, cleared local variables.

CAN 1:

sFilterConfig.FilterBank = 0; 

:

sFilterConfig.SlaveStartFilterBank = 14;

CAN2:

sFilterConfig.FilterBank = 14; 

:

sFilterConfig.SlaveStartFilterBank = 14;

I guess above config is correct because it is working now.

Also I'm using separate Rx FIFOs right now for dual CANs. Need to check if it works with a single FIFO. That's not my priority at this moment.

BTW, thanks for saving my time. I knew that you'd be the one to answer my question . ST community is filled with your valuable answers :smiling_face_with_halo: .

Cheers :beer_mug:

Yeah, I feel like I'm stuck here forever..

0693W000006FiS3QAK.gif

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Probably need unique filter bank for each

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MG.5
Associate II

Its okay as long as you enjoy what you do and get :heavy_dollar_sign::heavy_dollar_sign::heavy_dollar_sign: (assuming).

Parvez Akhtar
Associate II

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.