2015-08-05 03:14 AM
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.
#can #filtering #hal
2015-08-05 04:18 AM
sMB_FilterConfig_GPS.FilterIdHigh = 0x1000; (0x80<<5)
sMB_FilterConfig_GPS.FilterIdLow = 0x1000; (0x80<<5
sMB_FilterConfig_GPS.FilterMaskIdHigh = 0xF000;
sMB_FilterConfig_GPS.FilterMaskIdLow =0xF000;
2015-08-05 04:57 AM
Yes, because you picked 16 bit mode, and (X & 0) == 0 always.
2015-08-05 07:25 AM
Ok I was confused because on RM0091 p827 Figure 313 each filter have its own number or in my case I set up only Filter Number 1 (and
FilterMaskIdLow
+
FilterIdLow
would have been Filter number 2 if i understand well).
I would like to implement received data regarding to their provenance. I could do so thank to a different filter number but HAL_CAN_Receive(&MB_CanHandle,CAN_FIFO0, 20) function doesn't take into account of that number. Does that mean I need to create differentCAN_HandleTypeDef for each of node I want to treat differently? So, in this case that means I have to configure the transmission process for each of them even if it is the same:/*##-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;