SMT32 CAN2配置中遇到无法接收的问题

STM32 CAN2 配置中遇到无法接收的问题

STM32系列中带有两个CAN控制器,但是按照CAN1配置CAN2,非常容易导致无法接收和发送问题,主要是因为下面两个问题导致的。:
①STM32系列单片机中CAN1和CAN2共用滤波器,需在CAN 筛选器主寄存器 (CAN_FMR)中配置CAN2 起始存储区后CAN2才能使用筛选器。

CAN_SlaveStartBank(15); // can2筛选器组从15开始
CAN_FilterInitStructure.CAN_FilterNumber=15;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32λ
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
②CAN2作为从设备无法直接访问SRAM,因此在使能CAN2时钟时,首先要使能CAN1时钟才可以。
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);


你可能感兴趣的:(CAN)