我用两台单片机进行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);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
if((id & 0x7FF) == 0x7FF)
{
TxMessage.IDE = CAN_ID_EXT; //拓展ID
}
else
{
TxMessage.IDE = CAN_ID_STD; //标准ID
}
http://www.openedv.com/forum.php?mod=viewthread&tid=10328
我上面这样设置屏蔽滤波器uint16_t mask = 0xFFFF;就是设置为完全匹配才能接收,但不匹配的也能进接收中断;
我的问题是不满足过滤器设置也能收到消息,比如我16位ID标识符设置id1=00,id2=01;结果我另一台机发id=05的can帧他居然也能收到,有什么可能原因
论坛上的帖子我看了不少,按此设置的程序也没什么不同,有什么原因造成这种情况?
设置两个过滤器组,我设置的两个过滤器组,接收两个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;//
一周热门 更多>