在设置过滤器时,我是这样设置的:
#define MAKE_ADDR(a) (((a)&0x7f)<<21)
#define CAN_BOARDCAST_ADDR 0x7f
tmp2 = MAKE_ADDR(0x7f);
tmp = MAKE_ADDR(addr);
//tmp = 0;
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = tmp >> 16;
CAN_FilterInitStructure.CAN_FilterIdLow = tmp & 0x0ffff;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = tmp2 >> 16;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = tmp2 & 0x0ffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
tmp = MAKE_ADDR(CAN_BOARDCAST_ADDR);
CAN_FilterInitStructure.CAN_FilterNumber = 1;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = tmp >> 16;
CAN_FilterInitStructure.CAN_FilterIdLow = tmp & 0x0ffff;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = tmp >> 16;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = tmp & 0x0ffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
在发送CAN包时的ID是这样设的:
//这个包是针对目的地址是0x7f的终端
tmp = 0x5fe04044;
CANx->sTxMailBox[mailbox_id].TIR = tmp;
/* Set up the DLC */
CANx->sTxMailBox[mailbox_id].TDTR &= (uint32_t)0xFFFFFFF0;
CANx->sTxMailBox[mailbox_id].TDTR |= (dlc & 0x0f);
/* Set up the data field */
CANx->sTxMailBox[mailbox_id].TDLR = data[0];
CANx->sTxMailBox[mailbox_id].TDHR = data[1];
/* Request transmission */
CANx->sTxMailBox[mailbox_id].TIR |= TMIDxR_TXRQ;
但是问题是:接收端收不到数据 |