STM32F105 单独使用CAN2,接收中断不能触发,接收不到数据帧?求指教。。。
void CAN2_Config(uint8_t sjw,uint8_t bs1,uint8_t bs2,uint16_t pres)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* ´ò¿ªGPIOʱÖÓ¡¢AFIOʱÖÓ£¬CANʱÖÓ */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
/* CAN2 RX PB12 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* CAN2 TX PB13 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* CAN2 Enabling interrupt */
NVIC_InitStructure.NVIC_IRQChannel=CAN2_RX1_IRQn; // FIFO_1
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* CAN BaudRate = RCC_APB1PeriphClock/(CAN_SJW+CAN_BS1+CAN_BS2)/CAN_Prescaler */
CAN_DeInit(CAN2);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=DISABLE;
CAN_InitStructure.CAN_AWUM=DISABLE;
CAN_InitStructure.CAN_NART=DISABLE;
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=DISABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
//CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;
CAN_InitStructure.CAN_SJW=sjw;
CAN_InitStructure.CAN_BS1=bs1;
CAN_InitStructure.CAN_BS2=bs2;
CAN_InitStructure.CAN_Prescaler=pres;
CAN_Init(CAN2,&CAN_InitStructure); // CAN2
CAN_FilterInitStructure.CAN_FilterNumber=14; //
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_FIFO1; // FIFO1Ö¸Ïò¹ýÂËÆ÷
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN2,CAN_IT_FMP1,ENABLE); // CAN2
}
只有CAN1,CAN2同时初始化后,CAN2才能接收数据,这是哪里配置出问题啦?
|