搞了个GD32的开发板,用了例程测试一下CAN通讯,发现了 在回环模式下可以进入CAN的接收中断,可以看到接收到的数据,但是改成正常模式后,使用CAN分析仪就完全看不到内容,下面是代码
void Can0_init( void )
{
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_AF); //重映射时钟
// gpio_pin_remap_config(GPIO_CAN_FULL_REMAP,ENABLE);
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);
gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
can_deinit(CAN0);
//PA11 Rx PA12 Tx
// rcu_periph_reset_enable(RCU_CAN0RST);
// rcu_periph_reset_disable(RCU_CAN0RST);
//初始化CAN0
can_parameter_struct Can_InitStructure;
can_filter_parameter_struct Can_FilterInitStructure;
Can_InitStructure.time_triggered = DISABLE; //禁止事件触发通信
Can_InitStructure.auto_bus_off_recovery = DISABLE; //禁止离线恢复
Can_InitStructure.auto_wake_up = ENABLE; //允许自动唤醒
Can_InitStructure.auto_retrans = DISABLE; //禁止自动重传
Can_InitStructure.rec_fifo_overwrite = DISABLE; //禁止接收FIFO锁定
Can_InitStructure.trans_fifo_order = DISABLE; //禁止FIFO优先级
Can_InitStructure.working_mode = CAN_NORMAL_MODE; //正常通信模式 CAN_LOOPBACK_MODE CAN_NORMAL_MODE
//波特率 54M/(1+3+5)/12
Can_InitStructure.resync_jump_width = CAN_BT_SJW_1TQ; //再同步宽度补偿 1TQ
Can_InitStructure.time_segment_1 = CAN_BT_BS1_5TQ; //位段1长度
Can_InitStructure.time_segment_2 = CAN_BT_BS2_3TQ; //位段2长度
Can_InitStructure.prescaler = 12; //54M/12/(5+3+1) = 500kbps
can_init(CAN0, &Can_InitStructure);
//配置CAN过滤器
Can_FilterInitStructure.filter_list_high = 0x100<<5; //过滤器高字节
Can_FilterInitStructure.filter_list_low = 0x321<<5; //过滤器低字节
Can_FilterInitStructure.filter_mask_high = 0x105<<5; //过滤器掩码数高位
Can_FilterInitStructure.filter_mask_low = 0x108<<5; //过滤器掩码数低位
Can_FilterInitStructure.filter_fifo_number = CAN_FIFO0; //过滤器关联FIFO0
Can_FilterInitStructure.filter_number = 0;
Can_FilterInitStructure.filter_mode = CAN_FILTERMODE_LIST; //列表模式
Can_FilterInitStructure.filter_bits = CAN_FILTERBITS_16BIT; //16位
Can_FilterInitStructure.filter_enable = ENABLE;
can_filter_init(&Can_FilterInitStructure);
//配置中断
//can_interrupt_enable(CAN0, CAN_INTEN_RFFIE0);
can_interrupt_enable(CAN0, CAN_INTEN_RFNEIE0);
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
nvic_irq_enable(USBD_LP_CAN0_RX0_IRQn,8,0);
} |