AnsweredAssumed Answered

CAN filtering

Question asked by pwdusid on Aug 5, 2015
Latest reply on Aug 5, 2015 by pwdusid
HI, 

I am trying to make the CAN2.0A protocole working on my STM32F072 but datasheet for filter setting up is not easy to understand. 

I want MB_board only receive message from node with ID like : 0001XXXXXXX (X= don't care)
void MB_CAN_Config(void)
{
  CAN_FilterConfTypeDef  sMB_FilterConfig;
  CAN_FilterConfTypeDef  sMB_FilterConfig_GPS;
 
  static CanTxMsgTypeDef        MB_TxMessage;
  static CanRxMsgTypeDef        MB_RxMessage;
 
  /*##-1- Configure the CAN peripheral #######################################*/
  MB_CanHandle.Instance = CANx;
  MB_CanHandle.pTxMsg = &MB_TxMessage;
  MB_CanHandle.pRxMsg = &MB_RxMessage;
 
  MB_CanHandle.Init.TTCM = DISABLE;
  MB_CanHandle.Init.ABOM = DISABLE;
  MB_CanHandle.Init.AWUM = DISABLE;
  MB_CanHandle.Init.NART = DISABLE;
  MB_CanHandle.Init.RFLM = DISABLE;
  MB_CanHandle.Init.TXFP = DISABLE;
  MB_CanHandle.Init.Mode = CAN_MODE_NORMAL;
  MB_CanHandle.Init.SJW = CAN_SJW_1TQ;
  MB_CanHandle.Init.BS1 = CAN_BS1_6TQ;
  MB_CanHandle.Init.BS2 = CAN_BS2_8TQ;
  MB_CanHandle.Init.Prescaler = 2;
 
  if (HAL_CAN_Init(&MB_CanHandle) != HAL_OK)
  {
    /* Initiliazation Error */
    Error_Handler();
  }
 
  /*##-2- Configure the CAN Filter ###########################################*/
  sMB_FilterConfig_GPS.FilterNumber = 1;
  sMB_FilterConfig_GPS.FilterMode = CAN_FILTERMODE_IDMASK;
  sMB_FilterConfig_GPS.FilterScale = CAN_FILTERSCALE_16BIT;
  sMB_FilterConfig_GPS.FilterIdHigh = 0x1000; (0x80<<5)
  sMB_FilterConfig_GPS.FilterIdLow = 0x0000;
  sMB_FilterConfig_GPS.FilterMaskIdHigh = 0xF000;
  sMB_FilterConfig_GPS.FilterMaskIdLow = 0x0000;
  sMB_FilterConfig_GPS.FilterFIFOAssignment = 0;
  sMB_FilterConfig_GPS.FilterActivation = ENABLE;
  sMB_FilterConfig_GPS.BankNumber = 2;
 
  if (HAL_CAN_ConfigFilter(&MB_CanHandle, &sMB_FilterConfig_GPS) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }
  /*##-3- Configure Transmission process #####################################*/
  MB_CanHandle.pTxMsg->StdId = 0x000;
  MB_CanHandle.pTxMsg->ExtId = 0x00;
  MB_CanHandle.pTxMsg->RTR = CAN_RTR_DATA;
  MB_CanHandle.pTxMsg->IDE = CAN_ID_STD;
  MB_CanHandle.pTxMsg->DLC = 0;
}

For now, all message are read regardless of the type of node and their ID.

Outcomes