CAN过滤器和掩码 设置函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
CP_VOID CanSetFilter(CAN_NUM_TypeDef byDevNo,CP_BYTE byFilterNumber,CP_DWORD dwId,CP_DWORD dwMask,CP_BYTE bIsStdId)
{
assert_param(byFilterNumber<14);
assert_param(IS_CAN_IDTYPE(bIsStdId));
CAN_FilterInitTypeDef CAN_FilterInitStructure;
if(byDevNo == CAN_1)
{
CAN_FilterInitStructure.CAN_FilterNumber=byFilterNumber;//CPU默认CAN2使用0-13号过滤器
}
else
{
CAN_FilterInitStructure.CAN_FilterNumber=byFilterNumber+14;//CPU默认CAN2使用14-27号过滤器
}
dwId = (dwId << 3) & 0xFFFFFFF8;//0位预留0,1位表示数据帧or远程帧,2位表示标准ID or 扩展ID
dwId |= (((CP_DWORD)bIsStdId) & 0x00000007);
dwMask = (dwMask << 3) & 0xFFFFFFF8;//0位预留0,1位表示数据帧or远程帧,2位表示标准ID or 扩展ID
dwMask |= (((CP_DWORD)bIsStdId) & 0x00000007);
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=(CP_WORD)((dwId >> 16) & 0x0000FFFF);
CAN_FilterInitStructure.CAN_FilterIdLow=(CP_WORD)(dwId & 0x0000FFFF);
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=(CP_WORD)((dwMask >> 16) & 0x0000FFFF);
CAN_FilterInitStructure.CAN_FilterMaskIdLow=(CP_WORD)(dwMask & 0x0000FFFF);
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}