AnsweredAssumed Answered

STM32F091 CAN Filter Setup

Question asked by Yi.Junbo on Jun 29, 2015
Latest reply on Jul 1, 2015 by chahrayar.chahrazed
Hi, 

I'm using HAL functions for F0 and F1 to setup CAN filters to allow message only with global id (here is 0) and node id(here is 0x02) to be received. The F1(STM32F103CB) is working fine, but F0(STM32F091CC) only received the message with global id. If filters are disabled, then
F0 received all the message.

Any comments on this issue?
See the source codes below.

Thanks.


JYI

HAL_StatusTypeDef MX_CAN_Config(void)
{
     CAN_FilterConfTypeDef  sFilterConfig;
     uint32_t nodeAddress=(uint32_t)0x02;     // can node id to for rx message filtering

     /* Configure the CAN Filter 0 for FIFO 0 with node id */
    sFilterConfig.FilterNumber = 0;
    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
    sFilterConfig.FilterIdHigh = (nodeAddress << 7) & 0x3F80;     // 7-bit for rx message filtering
    sFilterConfig.FilterIdLow = 0;
    sFilterConfig.FilterMaskIdHigh = 0x3F80;
    sFilterConfig.FilterMaskIdLow = 0;
    sFilterConfig.FilterFIFOAssignment = CAN_FIFO0;
    sFilterConfig.FilterActivation = ENABLE;
    sFilterConfig.BankNumber = 14;

    if(HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
    {
         return HAL_ERROR;
    }
    
    /* Configure the CAN Filter 1 FIFO 0 for global id=0 */
    sFilterConfig.FilterNumber = 1;
    sFilterConfig.FilterIdHigh = 0;
    sFilterConfig.FilterFIFOAssignment = CAN_FIFO0;

    if(HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
    {
         return HAL_ERROR;
    }
   
    // set buffer pointers
    hcan.pTxMsg = &TxMessage;
    hcan.pRxMsg = &RxMessage;
    /* Configure Transmission process */
    hcan.pTxMsg->RTR = CAN_RTR_DATA;
    hcan.pTxMsg->IDE = CAN_ID_EXT;
    hcan.pTxMsg->DLC = 0;
    // enable can rx with interruptions
    HAL_CAN_Receive_IT(&hcan, CAN_FIFO0);
    HAL_CAN_Receive_IT(&hcan, CAN_FIFO1);

    return HAL_OK;
}

Outcomes