stm32f105 USB与CAN中断问题请教.

2019-10-12 14:05发布


在stm32f10x_it.c文件中是有USB中断,如下:
#ifndef STM32F10X_CL
void USB_LP_CAN1_RX0_IRQHandler(void)
{
  USB_Istr();
}
#endif




以下是CAN初始化函数:

static void CAN_GPIO_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

        GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);
       
        // RX
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;       
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        // TX
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
}

// NVIC
static void CAN_NVIC_Config(void)
{
        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);
}

// MODE
static void CAN_MODE_Config(void)
{
        CAN_InitTypeDef CAN_InitStructure;
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
       
        CAN_DeInit(CAN1);
        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_SJW = CAN_SJW_1tq;
        CAN_InitStructure.CAN_BS1 = CAN_BS1_12tq;
        CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;
        CAN_InitStructure.CAN_Prescaler = 9;
        CAN_Init(CAN1, &CAN_InitStructure);
}


static void CAN_Filter_Config(void)
{
        CAN_FilterInitTypeDef CAN_FilterInitStructure;
       
        CAN_FilterInitStructure.CAN_FilterNumber = 0;
        CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
        CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
        CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)0x1314<<3)&0xFFFF0000)>>16;
        CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)0x1314<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
        CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;
        CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;
        CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FilterFIFO0;
        CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
        CAN_FilterInit(&CAN_FilterInitStructure);
        CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}

void CAN_Config(void)
{
        CAN_GPIO_Config();
        CAN_NVIC_Config();
        CAN_MODE_Config();
        CAN_Filter_Config();
}

void CAN_SetMsg(void)
{
        TxMessage.ExtId = 0x1314;
        TxMessage.IDE = CAN_ID_EXT;
        TxMessage.RTR = CAN_RTR_DATA;
        TxMessage.DLC = 2;
        TxMessage.Data[0] = 0xAB;
        TxMessage.Data[1] = 0xCD;
}


void CAN1_RX0_IRQHandler(void)
{
        if(CAN_GetITStatus(CAN1, CAN_IT_FMP0) != RESET)
        {
                CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
                InsertCanQueue(RxMessage);               
               
                CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0);
        }
}


现在的问题是:
      USB中断是不能改的,但是USB与CAN是共存的(stm32f105系列),所以只能改CAN的中断,单独测试CAN接收发送使用此 USB_LP_CAN1_RX0_IRQHandler函数作为CAN的中断函数,是可以收发正常的.
      目前使用CAN1_RX0_IRQHandler此函数无法收到数据.
      请大神帮帮忙.


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。