再调试GD32F305的CAN通信时,配置好后用CAN分析仪识别不了波特率是咋回事,程序是按官方例程来的呀
CAN相关初始化程序:
void Can1_Init(void)
{
can_parameter_struct can_parameter;
can_filter_parameter_struct can_filter_parameter;
/* enable CAN0 clock */
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
/* configure CAN0 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_FULL_REMAP,ENABLE);
can_struct_para_init(CAN_INIT_STRUCT,&can_parameter);
can_struct_para_init(CAN_FILTER_STRUCT,&can_filter_parameter);
can_deinit(CAN0);
/* initialize CAN parameters */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = DISABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.no_auto_retrans = DISABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode = 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;
can_parameter.prescaler = 12;
/* initialize CAN */
can_init(CAN0, &can_parameter);
/* initialize filter */
can_filter_parameter.filter_number = 0;
can_filter_parameter.filter_mode = CAN_FILTERMODE_MASK;
can_filter_parameter.filter_bits = CAN_FILTERBITS_32BIT;
can_filter_parameter.filter_list_high = 0x0000;
can_filter_parameter.filter_list_low = 0x0000;
can_filter_parameter.filter_mask_high = 0x0000;
can_filter_parameter.filter_mask_low = 0x0000;
can_filter_parameter.filter_fifo_number = CAN_FIFO0;
can_filter_parameter.filter_enable = ENABLE;
can_filter_init(&can_filter_parameter);
nvic_irq_enable(CAN0_RX0_IRQn,0,1);
/* enable can receive FIFO0 not empty interrupt */
can_interrupt_enable(CAN0, CAN_INT_RFNE0);
}
void CAN0_RX0_IRQHandler(void)
{
/* check the receive message */
can_message_receive(CAN0, CAN_FIFO0, &g_receive_message1);
CAN_Receive_Flag=1;
}
以上就是初始化程序,连接CAN分析仪识别不了波特率不知道是咋回事。
|