/********************************************************************************************************************************************************************************************
**函数名称: CanSetRxFilter
**函数功能:
**入口参数:
**返回参数:
*********************************************************************************************************************************************************************************************/
void CanSetRxFilter(BYTE num,UINT32 FilterID1,UINT32 FilterID2)
{
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_FilterInitStructure.CAN_FilterNumber = num;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
printf("\r\n num: %d FilterID1: %08x FilterID2: %08x",num,FilterID1,FilterID2);
if(FilterID1 > 0x800)
{
CAN_FilterInitStructure.CAN_FilterIdHigh=((FilterID1 << 3 )>> 16) & 0xffff;
CAN_FilterInitStructure.CAN_FilterIdLow=((FilterID1 << 3)& 0xffff) | CAN_ID_EXT;
}
else
{
CAN_FilterInitStructure.CAN_FilterIdHigh = FilterID1 << 5;
CAN_FilterInitStructure.CAN_FilterIdLow = 0|CAN_ID_STD;
}
if(FilterID2 > 0x800)
{
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=((FilterID2 << 3 )>> 16) & 0xffff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=((FilterID2 << 3)& 0xffff) | CAN_ID_EXT;
}
else
{
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = FilterID2 << 5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0|CAN_ID_STD;
}
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}
|