我用两台单片机进行CAN通信试验,收发都成功了,但发现了一个问题,设置的过滤器id为00和01,结果另一台单片机发送ID
StdId无论改为什么这台单片机都能收到消息,怎么回事?难道双节点通信不需要用ID标识符过滤消息?
这是我的can过滤器设置:
void CAN1_Config16BitFilter(uint16_t id1, uint16_t id2)
{
CAN_FilterInitTypeDef CAN_FilterInitStructure;
uint16_t mask = 0xFFFF;
CAN_FilterInitStructure.CAN_FilterNumber = 1;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;//IDÄ£ê½
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = (id1 << 5);
CAN_FilterInitStructure.CAN_FilterIdLow = (id2 << 5);
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (mask << 5);
CAN_FilterInitStructure.CAN_FilterMaskIdLow = (mask << 5);
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0; //FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
设置两个过滤器组,我设置的两个过滤器组,接收两个ID返还自己的ID值加数据是可以的
CAN_FilterInitStructure.CAN_FilterNumber=0; //过滤器0
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32位
#if ID_EXT_En//扩展帧滤波器全部匹配
CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)0x0013<<3)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow=(((u32)0x0013<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;//0x0000;//
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;//0x0000;//
CAN_FilterInitStructure.CAN_FilterNumber=1; //过滤器1
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32位
#if ID_EXT_En//扩展帧滤波器全部匹配
CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)0x0014<<3)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow=(((u32)0x0014<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;//0x0000;//
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;//0x0000;//
一周热门 更多>