cancel
Showing results for 
Search instead for 
Did you mean: 

Handling filters for CAN1&CAN2 and FIFO0 & FIFO1

Steven.D
Associate II

Hi everybody,

I'm using an STM32F469BI and I'm trying to receive on both Can1 and Can2, and handle messages on both FIFOs. For example, my board can be commanded to wait for messages on CAN1 FIFO0 and CAN2 FIFO0 or CAN1 FIFO0 and CAN2 FIFO1,..

So i'm able to receive on both CAN but my problem is either I do not receive on both fifos or my messages filters are not handled properly (for example : I want a message filter only on CAN1 but it is also applied to CAN2 ).

I did enabled and handled fifo rx0 and rx1 interrupts for can1 and can2.

I suspect something related to the Filter numbers and/or the start slave bank number. But the reference manual is not clear on this I think. So i don't know how to handle these parameters properly Here's my code :

------

bool bHILMCP2562_Initialize(eCanInterface __e_CanInterface, eCanBaudrate __e_Can2Baudrate)

{

   CAN_HandleTypeDef    *__pt_CanHandle;

 bool __b_Result = true;

 /* Enable CAN clock                                                          */

 __CAN1_CLK_ENABLE();

 __CAN2_CLK_ENABLE();

   if(__e_CanInterface == e_Can1)

 {

      _t_Can1Structure.Instance = CAN1;

      _t_Can1Structure.pTxMsg = &_t_TxCan1Message;

      _t_Can1Structure.pRxMsg = &_t_RxCan1Message;

      _t_Can1Structure.Init.TTCM = DISABLE;

      _t_Can1Structure.Init.ABOM = DISABLE;

      _t_Can1Structure.Init.AWUM = DISABLE;

      _t_Can1Structure.Init.NART = DISABLE;

      _t_Can1Structure.Init.RFLM = DISABLE;

      _t_Can1Structure.Init.TXFP = ENABLE;

      _t_Can1Structure.Init.Mode = CAN_MODE_NORMAL;

      /* CAN1 has always a baudrate of 250 kbps */

      _t_Can1Structure.Init.SJW = CAN_SJW_3TQ;

      _t_Can1Structure.Init.BS1 = CAN_BS1_9TQ;

      _t_Can1Structure.Init.BS2 = CAN_BS2_2TQ;

      _t_Can1Structure.Init.Prescaler = 14U;

      __pt_CanHandle = &_t_Can1Structure;

   }

   else if(__e_CanInterface == e_Can2) /* Note that CAN1 has to be initialized for CAN2 to be working */

 {

      _t_Can2Structure.Instance = CAN2;

      _t_Can2Structure.pTxMsg = &_t_TxCan2Message;

      _t_Can2Structure.pRxMsg = &_t_RxCan2Message;

      _t_Can2Structure.Init.TTCM = DISABLE;

      _t_Can2Structure.Init.ABOM = DISABLE;

      _t_Can2Structure.Init.AWUM = DISABLE;

      _t_Can2Structure.Init.NART = DISABLE;

      _t_Can2Structure.Init.RFLM = DISABLE;

      _t_Can2Structure.Init.TXFP = ENABLE;

      _t_Can2Structure.Init.Mode = CAN_MODE_NORMAL;

      vHILMCP2562_SetCan2BaudRate(__e_Can2Baudrate);

      __pt_CanHandle = &_t_Can2Structure;

 }

   /* Power off transceiver */

 vHILMCP2562_SetTransceiverPower(__e_CanInterface, false);

   if(HAL_CAN_Init(__pt_CanHandle) != HAL_OK)

 {

   assert_failed((uint8_t*)__FILE__, __LINE__);

      __b_Result = false;

 }

   vInitInterrupts();

 return __b_Result;

}

-------------

bool bHILMCP2562_AddMsgFilter(eCanInterface __e_CanInterface, uint32_t __u32_CanID, eCanMask __e_IdentifierMask, uint8_t __u8_FilterIndex, uint8_t __u8_FilterFIFO, uint8_t __u8_StartSlaveBankFilter)

{

   CAN_FilterConfTypeDef  __t_CanFilterInitStructure;

   CAN_HandleTypeDef      *__pt_CanHandle;

   bool                   __b_Result = false, __b_IdExtended = false;

   __pt_CanHandle = (__e_CanInterface == e_Can1) ? &_t_Can1Structure : &_t_Can2Structure;

   __b_IdExtended = (__u32_CanID <= 0x1FFFFFFFU) && (!__u32_CanID <= 0x000007FFU);

   __t_CanFilterInitStructure.FilterMode = CAN_FILTERMODE_IDMASK;

   __t_CanFilterInitStructure.FilterNumber = __u8_FilterIndex; /* gets incremented each time -> from 0 to 27*/

   if (__b_IdExtended)

   {

      __t_CanFilterInitStructure.FilterScale = CAN_FILTERSCALE_32BIT;

      __t_CanFilterInitStructure.FilterIdHigh = (uint16_t)((__u32_CanID << 3U) >> 2U*BYTE_LENGTH);

      __t_CanFilterInitStructure.FilterIdLow = (uint16_t)(__u32_CanID << 3U);

      __t_CanFilterInitStructure.FilterMaskIdHigh = (uint16_t)(((uint32_t)(__e_IdentifierMask) << 3U) >> 2U*BYTE_LENGTH);

      __t_CanFilterInitStructure.FilterMaskIdLow = (uint16_t)((uint32_t)(__e_IdentifierMask) << 3U);

   }

   else

   {

      __t_CanFilterInitStructure.FilterScale = CAN_FILTERSCALE_16BIT;

      __t_CanFilterInitStructure.FilterIdHigh = (uint16_t)((__u32_CanID << 5U) >> 2U*BYTE_LENGTH);

      __t_CanFilterInitStructure.FilterIdLow = (uint16_t)(__u32_CanID << 5U);

      __t_CanFilterInitStructure.FilterMaskIdHigh = (uint16_t)((__e_IdentifierMask << 5U) >> 2U*BYTE_LENGTH);

      __t_CanFilterInitStructure.FilterMaskIdLow = (uint16_t)(__e_IdentifierMask << 5U);

   }

   __t_CanFilterInitStructure.FilterFIFOAssignment = (__u8_FilterFIFO == 0U) ? CAN_FILTER_FIFO0 : CAN_FILTER_FIFO1;

   __t_CanFilterInitStructure.FilterActivation = ENABLE;

   __t_CanFilterInitStructure.BankNumber = 28U; /* To change */

   if(HAL_CAN_ConfigFilter(__pt_CanHandle, &__t_CanFilterInitStructure) == HAL_OK)

   {

      __b_Result = true;

   }

   return __b_Result;

}

--------------------

P.S. : I noted that if don't go, at least once, through the function that calls HAL_CAN_ConfigFilter, i can't receive anything. Is this normal behaviour ?

Thanks in advance for the help =)

0 REPLIES 0