This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

/b STM32F107 CAN2 interrupt proble

Hi..

STM32F107 peripheral the circuit under test

CAN1, CAN2, use the source code that implements.

In CAN1 Send and recive (interrupt) operation, but CAN2 Send normal operation, not recive(intterupt) proble.

attach my source code.

I made a mistake pointed out in the request.

//CAN1, CAN2 Init

/pre void CAN_PortInit(uint8_t nSelect)
/pre{
/pre GPIO_InitTypeDef GPIO_InitStructure;
/pre
/pre RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/pre RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/pre if( nSelect == 1 ) //CAN2
/pre {
/pre RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
/pre RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/pre }
/pre /* Configure CAN pin: RX */
/pre GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
/pre GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
/pre GPIO_Init(GPIOA, &GPIO_InitStructure);
/pre
/pre /* Configure CAN pin: TX */
/pre GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
/pre GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
/pre GPIO_Init(GPIOA, &GPIO_InitStructure);
/pre
/pre if( nSelect == 1) //CAN2
/pre {
/pre /* Configure CAN pin: RX */
/pre GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
/pre GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
/pre GPIO_Init(GPIOB, &GPIO_InitStructure);
/pre
/pre /* Configure CAN pin: TX */
/pre GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
/pre GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
/pre GPIO_Init(GPIOB, &GPIO_InitStructure);
/pre }
/pre
/pre}

/pre //CAN1, CAN2 Configuration
/pre void CAN_Configuration(CAN_TypeDef * CANx, uint8_t nCanBaudRate)
/pre{
/pre CAN_InitTypeDef CAN_InitStructure;
/pre CAN_FilterInitTypeDef CAN_FilterInitStructure;
/pre
/pre /* CAN register init */
/pre CAN_DeInit(CANx);
/pre CAN_StructInit(&CAN_InitStructure);
/pre
/pre /* CAN cell init */
/pre CAN_InitStructure.CAN_ABOM=DISABLE;
/pre CAN_InitStructure.CAN_AWUM=DISABLE;
/pre CAN_InitStructure.CAN_NART=DISABLE;
/pre CAN_InitStructure.CAN_RFLM=DISABLE;
/pre CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
/pre
/pre CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
/pre CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
/pre CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
/pre CAN_InitStructure.CAN_Prescaler=4; //72MHz/2=36MHz=PCLK1 / 4 => 9000KHz / (1+10+7) => 500KHz
/pre CAN_Init(CANx, &CAN_InitStructure);
/pre
/pre /* CAN filter init */
/pre ... omitted ....
/pre CAN_FilterInit(&CAN_FilterInitStructure);
/pre
/pre CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);
/pre
/pre}

/pre//NVIC Configuration
/pre void NVIC_Configuration(void)
/pre{
/pre NVIC_InitTypeDef NVIC_InitStructure;
/pre
/pre#ifdef VECT_TAB_RAM
/pre /* Set the Vector Table base location at 0x20000000 */
/pre NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
/pre#else /* VECT_TAB_FLASH */
/pre /* Set the Vector Table base location at 0x08000000 */
/pre NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
/pre#endif
/pre
/pre /* Configure the NVIC Preemption Priority Bits */
/pre NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/pre
/pre /* Enable the USART1 Interrupt */
/pre NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
/pre NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x1;
/pre NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
/pre NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/pre NVIC_Init(&NVIC_InitStructure);
/pre
/pre /* Enable the USART2 Interrupt */
/pre NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
/pre NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x1;
/pre NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
/pre NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/pre NVIC_Init(&NVIC_InitStructure);

/pre /* Enable the USART3 Interrupt */
/pre NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
/pre NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x1;
/pre NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
/pre NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/pre NVIC_Init(&NVIC_InitStructure);

/pre /* Enable CAN1 RX0 interrupt IRQ channel */
/pre NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
/pre NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
/pre NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
/pre NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/pre NVIC_Init(&NVIC_InitStructure);

/pre /* Enable CAN2 RX0 interrupt IRQ channel */
/pre NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
/pre NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x1;
/pre NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
/pre NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/pre NVIC_Init(&NVIC_InitStructure);
/pre
/pre}
/pre
/pre void CAN2_RX0_IRQHandler(void)
/pre {
/pre u8 pCanData[8];
/pre u32 u32NumData;
/pre u32 u32RW;
/pre u32 u32CANID;
/pre int i;
/pre
/pre CanRxMsg RxMessage;
/pre
/pre printf("CAN2_RX0_IRQHandler ....\r\n");
/pre
/pre
/pre RxMessage.StdId=0x00;
/pre RxMessage.ExtId=0x00;
/pre RxMessage.IDE=0;
/pre RxMessage.DLC=0;
/pre RxMessage.FMI=0;
/pre
/pre CAN_Receive(CAN2, CAN_FIFO0, &RxMessage);
/pre u32NumData=RxMessage.DLC;
/pre for(i=0;i<u32NumData;i++)
/pre {
/pre pCanData[i]=RxMessage.Data[i];
/pre }
/pre u32CANID=RxMessage.StdId;
/pre if(RxMessage.RTR==CAN_RTR_REMOTE)
/pre u32RW=0;
/pre else
/pre u32RW=1;
/pre
/pre printf("CAN_Receive ID : %d\r\n", RxMessage.StdId);
/pre CAN_Receive(CAN2, CAN_FIFO0, &RxMessage);
/pre
/pre for( i=0; i< RxMessage.DLC; i++ ) printf("D[%1d]=%02x ", i, RxMessage.Data[i] );
/pre}

Kind Regards.

0