用GD32F450调试CAN时,发现第二个CAN进入不了中断。通过请教专业人士,需要将第二个CAN的配置成
/* initialize filter */
/* CAN1 filter number */
can_filter1.filter_number = 15;
/* initialize filter */
can_filter1.filter_mode = CAN_FILTERMODE_MASK;
can_filter1.filter_bits = CAN_FILTERBITS_32BIT;
can_filter1.filter_list_high = 0x0000;
can_filter1.filter_list_low = 0x0000;
can_filter1.filter_mask_high = 0x0000;
can_filter1.filter_mask_low = 0x0000;
can_filter1.filter_fifo_number = CAN_FIFO0;
can_filter1.filter_enable = ENABLE;
can_filter_init(&can_filter1);
/* enable CAN receive FIFO1 not empty interrupt */
can_interrupt_enable(CAN1, CAN_INTEN_RFNEIE0);
下面是GD32F450两路CAN的完整的初始化代码,配置完成两路CAN即可进入接收中断
void can_networking_init(void)
{
can_parameter_struct can_parameter;
can_filter_parameter_struct can_filter;
can_filter_parameter_struct can_filter1;
/* enable can clock */
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_CAN1);
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB);
/* configure CAN0 GPIO, CAN0_TX(PA12) and CAN0_RX(PA11) */
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_11);
gpio_af_set(GPIOA, GPIO_AF_9, GPIO_PIN_11);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12);
gpio_af_set(GPIOA, GPIO_AF_9, GPIO_PIN_12);
/* configure CAN1 GPIO, CAN0_TX(PB13) and CAN0_RX(PB12) */
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12);
gpio_af_set(GPIOB, GPIO_AF_9, GPIO_PIN_12);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_13);
gpio_af_set(GPIOB, GPIO_AF_9, GPIO_PIN_13);
/* initialize CAN register */
can_deinit(CAN0);
can_deinit(CAN1);
/* initialize CAN */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = DISABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.auto_retrans = DISABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode =CAN_NORMAL_MODE;// CAN_LOOPBACK_MODE;//CAN_NORMAL_MODE;
can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
can_parameter.time_segment_1 = CAN_BT_BS1_5TQ;
can_parameter.time_segment_2 = CAN_BT_BS2_4TQ;
/* baudrate 1Mbps */
can_parameter.prescaler = 5;
can_init(CAN0, &can_parameter);
can_init(CAN1, &can_parameter);
/* initialize filter */
/* CAN0 filter number */
can_filter.filter_number = 0;
/* initialize filter */
can_filter.filter_mode = CAN_FILTERMODE_MASK;
can_filter.filter_bits = CAN_FILTERBITS_32BIT;
can_filter.filter_list_high = 0x0000;
can_filter.filter_list_low = 0x0000;
can_filter.filter_mask_high = 0x0000;
can_filter.filter_mask_low = 0x0000;
can_filter.filter_fifo_number = CAN_FIFO0;
can_filter.filter_enable = ENABLE;
can_filter_init(&can_filter);
/* enable CAN receive FIFO0 not empty interrupt */
can_interrupt_enable(CAN0, CAN_INTEN_RFNEIE0);
/* initialize filter */
/* CAN1 filter number */
can_filter1.filter_number = 15;
/* initialize filter */
can_filter1.filter_mode = CAN_FILTERMODE_MASK;
can_filter1.filter_bits = CAN_FILTERBITS_32BIT;
can_filter1.filter_list_high = 0x0000;
can_filter1.filter_list_low = 0x0000;
can_filter1.filter_mask_high = 0x0000;
can_filter1.filter_mask_low = 0x0000;
can_filter1.filter_fifo_number = CAN_FIFO0;
can_filter1.filter_enable = ENABLE;
can_filter_init(&can_filter1);
/* enable CAN receive FIFO1 not empty interrupt */
can_interrupt_enable(CAN1, CAN_INTEN_RFNEIE0);
/* configure CAN0 NVIC */
nvic_irq_enable(CAN0_RX0_IRQn,0,0);
nvic_irq_enable(CAN1_RX0_IRQn,0,0);
}
添加相应的中断函数即可
void CAN0_RX0_IRQHandler(void)
void CAN1_RX0_IRQHandler(void)