各位大神,调试了很久,无法进入CAN1中断服务函数,求助!!!下面是相关源码!任务主体
void AppTaskTestCan(void)
{
OS_ERR err;
CPU_TS ts;
LED2_Off();
while(1)
{
OSSemPend(&App_TestCAN1Sem, //App_UserLEDSem当换成定时器中断发出的信号量里LED翻转 //App_TestCAN1Sem 进不了CAN1接收中断,所以也没有App_TestCAN1Sem出来
0,
OS_OPT_PEND_BLOCKING,
&ts,
&err
);
BSP_LED_Toggle(2);
}
}
CAN1配置函数
void BSP_Can1_Init(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* CAN Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap2_CAN1,ENABLE);
/* Configure CAN1 pin: RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure CAN1 pin: TX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
CAN_DeInit(CAN1);
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 = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_8tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler=9;
CAN_Init(CAN1,&CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 0;
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 = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);
//
BSP_IntVectSet(BSP_INT_ID_CAN1_RX0, CAN1_RX0_ISR_Handler);
BSP_IntEn(BSP_INT_ID_CAN1_RX0);
}
CAN1中断服务函数,对应于BSP_IntVectSet(BSP_INT_ID_CAN1_RX0, CAN1_RX0_ISR_Handler);
void CAN1_RX0_ISR_Handler(void)
{
OS_ERR err;
CanRxMsg RxMessage;
unsigned char i;
if(CAN_GetFlagStatus(CAN1,CAN_IT_FMP0) != RESET)
{
BSP_LED_Toggle(2);
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
for(i = 0;i < 8; i ++)
{
CAN1_DATA = RxMessage.Data;
}
CAN_ClearITPendingBit(CAN1,CAN_IT_FMP0);
OSSemPost(&App_TestCAN0Sem,
OS_OPT_POST_ALL ,
&err
);
}
}
另:#define BSP_INT_ID_CAN1_RX0 20 /* CAN1 RX0 Interrupts */
用同样的方式(
BSP_IntVectSet(BSP_INT_ID_TIM2, BSP_Timer2_Int);
BSP_IntVectSet(BSP_INT_ID_CAN1_RX0, CAN1_RX0_ISR_Handler);
),定时器2可以实现中断,但CAN1就是不行,求大神帮忙!!!不胜感激!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
补充一下,裸机可以进入中断,另外,App_TestCAN1Sem,App_TestCAN0Sem,这两个其实是一样的,是我发贴的以为不对,临时改的,这里没有问题..麻烦各位大神看看,那里的问题,
一周热门 更多>