|
CAN报文通过中断接收和发送,CAN_RX , CAN_TX也分别重映射到 PA11和PA12脚上,AFIO时钟和CAN时钟也都使能了,就是不能进中断,求助啊,急。。。。。
程序中的部分如下:
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap1_CAN , ENABLE);
//-------------- PA11 as CAN_Rx--------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//-------------- PA12 as CAN_Tx--------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_DeInit();
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=DISABLE;
CAN_InitStructure.CAN_AWUM=DISABLE;
CAN_InitStructure.CAN_NART=ENABLE;
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_13tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = 18;
CAN_Init(&CAN_InitStructure);
CAN->BTR |= 0xC0000000;
CAN_FilterInitStructure.CAN_FilterNumber=0; CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList; CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh=0x01<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000; CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0; CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN_IT_TME, ENABLE);
CAN_ITConfig(CAN_IT_BOF,ENABLE);
void USB_LP_CAN_RX0_IRQHandler()
{
CanRxMsg RxMessage;
u8 i = 0;
RxMessage.StdId = 0;
RxMessage.ExtId = 0;
RxMessage.IDE = 0;
RxMessage.RTR = CAN_RTR_DATA;
RxMessage.DLC = 8;
RxMessage.FMI = 0;
for(;i <8 ;i++)
{
RxMessage.Data = 0;
}
CAN_Receive(CAN_FIFO0,&RxMessage);
if(MCB_ID == RxMessage.StdId) //为所需的报文时,将其放入can报文队列
EnRecQueue(&recv_can_que, &RxMessage);
}
void USB_HP_CAN_TX_IRQHandler()
{
CanTxMsg TxMessage;
if(!DeSendQueue(&send_can_que,&TxMessage)) //在发送报文队列中取报文发送
SendFrame(&TxMessage);
}
在正常模式、静默环回和环回模式下都进不了中断。。。。。。
求高手解救啊,急啊。。。。。。
|
|