各位兄弟,我来求助了,我用到Stm32f107的,我用到CAN2,CAN2可以发,但进不了接收中断,求真像。
相关代码如下:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,ENABLE);
。。
void CAN_Configuration(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_DeInit(CAN2);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
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_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CAN2, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber=14;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=0;
CAN_FilterInitStructure.CAN_FilterIdLow=0;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(CAN2, &CAN_FilterInitStructure);
/* transmit */
TxMessage.StdId = 0x321;
TxMessage.ExtId = 0x01;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 1;
}
。。
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;////
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
。。
void CAN2_RX0_IRQHandler(void)
{
//我在这里放个断点,用另一个开发板发送CAN数据,进不了中断。另一个发送的是一定没问题的
CAN_Receive(CAN2, CAN_FIFO0, &RxMessage);
//
} |