cancel
Showing results for 
Search instead for 
Did you mean: 

[RESOLVED] STM32F107VC CAN Slave

Yannick Dannel
Associate II
Posted on January 22, 2018 at 15:04

Dear,

I work on CAN bus with STM32F107 MCU.

I arrived to configured CAN 1 with the help of 'CAN Networking' example to send and receive CAN frame but when I try to use the CAN 2 (Slave CAN)? I only can send CAN frame. I can't receive CAN frame.

So my CAN is correctly configured because I can send CAN frame. I think the problem is with the filters (I don't completely understand how it work).

// CAN 2 configuration

can2HwHandle.Init.Prescaler = 18;

can2HwHandle.Init.Mode = CAN_MODE_NORMAL;

can2HwHandle.Init.SJW = CAN_SJW_1TQ;

can2HwHandle.Init.BS1 = CAN_BS1_8TQ;

can2HwHandle.Init.BS2 = CAN_BS2_7TQ;

can2HwHandle.Init.TTCM = DISABLE;

can2HwHandle.Init.ABOM = DISABLE;

can2HwHandle.Init.AWUM = DISABLE;

can2HwHandle.Init.NART = DISABLE;

can2HwHandle.Init.RFLM = DISABLE;

can2HwHandle.Init.TXFP = DISABLE;

// CAN 2 clock enable

__HAL_RCC_CAN2_CLK_ENABLE();

if ( HAL_CAN_Init(&can2HwHandle) == HAL_OK ) {

   filterConfig.FilterNumber = 0;

   filterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

   filterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

   filterConfig.FilterIdHigh = 0;

   filterConfig.FilterIdLow = 0;

   filterConfig.FilterMaskIdHigh = 0;

   filterConfig.FilterMaskIdLow = 0;

   filterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;

   filterConfig.FilterActivation = ENABLE;

   filterConfig.BankNumber = 14;

      if ( HAL_CAN_ConfigFilter(&can2HwHandle, &filterConfig) == HAL_OK) {

         if ( HAL_CAN_Receive_IT(&can2HwHandle,CAN_FIFO0) == HAL_OK ) {

            // CAN 2 ITs configuration.

            HAL_NVIC_SetPriority(CAN2_TX_IRQn,0,15);

            HAL_NVIC_EnableIRQ(CAN2_TX_IRQn);

            HAL_NVIC_SetPriority(CAN2_RX0_IRQn,0,15);

            HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);

         }

      }

   }

I use the same configuration as example but it don't work.

Maybe someone can help me ?

1 ACCEPTED SOLUTION

Accepted Solutions
Yannick Dannel
Associate II
Posted on January 23, 2018 at 08:27

Dear,

I resolved the problem. Thank your both. The solution with the same number for FilterNumber et BankNumber like suggest Mario Popovic. But to work, I needed to used CAN1 when I configured CAN2 filters.

Regards

View solution in original post

6 REPLIES 6
Szymon PANECKI
Senior III
Posted on January 22, 2018 at 15:14

Hello Yannick,

Could you please try to change CAN filter configuration for the following?:

  • filterConfig.FilterNumber = 14;  //change from 0 to 14

  • filterConfig.BankNumber = 0;  //change from 14 to 0

Regards

Szymon

Yannick Dannel
Associate II
Posted on January 22, 2018 at 15:20

Dear,

I trying with your configuration but I don't receive CAN frame.

Regards

Mario Popovic
Associate III
Posted on January 22, 2018 at 16:03

I think your problem is with the filter and bank configuration. The filter bank specifies which filter numbers are assigned to CAN2. If it's set to 14, then filters 14-27 are assigned to CAN2. So when initializing the filters for CAN2 you must start with

FilterNumber

 = BankNumber and increment from there.

For your CAN2 initialization you need to use both:

  • filterConfig.FilterNumber = 14;

  • filterConfig.BankNumber = 14;

Posted on January 22, 2018 at 15:33

Hello Yannick,

Thanks for your feedback. Some time ago I was developing a simple application for STM32F2, which was demonstrating usage of CAN1 and CAN2, both transission and reception. I compared your code with mine and main difference which I found was the

FilterNumber and

BankNumber values. I agree with you that most probably your issue is related to wrong filter configuration.

Please find attached my main.c and it.c files (with interrupts handlers). Maybe you can review themand you will manage to find more differences between your code and mine.

Regards

Szymon

________________

Attachments :

main.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy7H&d=%2Fa%2F0X0000000b49%2F11bD9S4jjDxLf.vHqZu7LNmD5WIv0rYRXW_p_MFNfqg&asPdf=false

stm32f2xx_it.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy7C&d=%2Fa%2F0X0000000b48%2F_zc_jb.QbnC6v2H56LWW5zzoxdWTepRFD6VJ60YuNIA&asPdf=false
Yannick Dannel
Associate II
Posted on January 23, 2018 at 08:27

Dear,

I resolved the problem. Thank your both. The solution with the same number for FilterNumber et BankNumber like suggest Mario Popovic. But to work, I needed to used CAN1 when I configured CAN2 filters.

Regards

Posted on March 29, 2018 at 15:25

Hello, How did you solve ?