can发送数据:
/* transmit 1 message */
TxMessage.StdId=0x1234;
TxMessage.ExtId=0x5678;
TxMessage.IDE=CAN_ID_EXT;
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.DLC=2;
TxMessage.Data[0]=0x55;
TxMessage.Data[1]=0x55;
CAN_Transmit(&TxMessage);
can接收数据:
void USB_LP_CAN_RX0_IRQHandler(void)
{
CanRxMsg RxMessage;
RxMessage.StdId=0x1234;
RxMessage.ExtId=0x5678;
RxMessage.IDE=0;
RxMessage.DLC=2;
RxMessage.FMI=0;
RxMessage.Data[0]=0x00;
RxMessage.Data[1]=0x00;
CAN_Receive(CAN_FIFO0, &RxMessage);
ret = 1;
}
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber=1;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=0x1234;
CAN_FilterInitStructure.CAN_FilterIdLow=0x5678;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xffff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* CAN FIFO0 message pending interrupt enable */
CAN_ITConfig(CAN_IT_FMP0, ENABLE);
只要屏蔽器的值为零,就能接收到数据,现在想搞多借点通信,屏蔽器CAN_FilterMaskIdHigh和CAN_FilterMaskIdLow值都为0xffff;时接收不到数据。现在的主要问题是我不知道过滤器和屏蔽器的值怎么设置!谢谢了! |