gd32c103 can使用,单总线上有其他节点,其他节点会间隔发数据,发现C103只接收没问题,但是一发数据,过后就会出现异常(离线、总线错误什么的),收不到其他节点的数据了,除非使能了离线自动恢复会自己恢复,想请教一下这个是什么问题,如何解决,还是我配置不对,懂的大佬帮忙看看,配置如下:void CAN0_Init(void)
{
/* enable CAN clock */
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
/* configure CAN1 GPIO */
gpio_init(GPIOB,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_8);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_9);
gpio_pin_remap_config(GPIO_CAN0_PARTIAL_REMAP, ENABLE);
can0_networking_init();
/* configure CAN0 NVIC */
nvic_irq_enable(CAN0_RX0_IRQn, 0, 2);
/* enable CAN receive FIFO0 not empty interrupt */
can_interrupt_enable(CAN0, CAN_INT_RFNE0);
}
void can0_networking_init(void)
{
can_parameter_struct can_parameter;
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
/* initialize CAN register */
can_deinit(CAN0);
/* initialize CAN */
can_parameter.time_triggered = DISABLE; //时间触发通信模式
can_parameter.auto_bus_off_recovery = DISABLE ; //离线自动恢复
can_parameter.auto_wake_up = DISABLE; //自动唤醒
can_parameter.auto_retrans = ENABLE; //自动重发
can_parameter.rec_fifo_overwrite = ENABLE; //接收FIFO满时覆盖
can_parameter.trans_fifo_order = ENABLE; //发送FIFO顺序
can_parameter.working_mode = CAN_NORMAL_MODE;
// can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
// can_parameter.time_segment_1 = CAN_BT_BS1_6TQ;
// can_parameter.time_segment_2 = CAN_BT_BS2_3TQ;
can_init(CAN0, &can_parameter);
/* config CAN0 baud rate */
can_frequency_set(CAN0, 250000);
can_filter_mask_mode_init(DEV_CAN0_ID, DEV_CAN0_MASK, CAN_EXTENDED_FIFO0, 0);
}
|