CAN 配置125k 及一下都可正常收发 125k 以上CAN无法收发数据请大佬帮忙看下
void CAN0_Config(u16 CAN_BAUDRATE)
{
can_parameter_struct can_parameter;
can_filter_parameter_struct can_filter;
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
can_struct_para_init(CAN_FILTER_STRUCT, &can_filter);
/* initialize CAN register */
can_deinit(CAN0);
/* initialize CAN parameters */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = ENABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.auto_retrans = ENABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode = CAN_NORMAL_MODE;
can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
// can_parameter.time_segment_1 = CAN_BT_BS1_8TQ;
// can_parameter.time_segment_2 = CAN_BT_BS2_1TQ;
can_parameter.time_segment_1 = CAN_BT_BS1_8TQ;
can_parameter.time_segment_2 = CAN_BT_BS2_1TQ;
/* 1MBps */
if (CAN_BAUDRATE == 1000) //AHB1 主频60M / 1000
{
can_parameter.prescaler = 6;
}
/* 500KBps */
else if (CAN_BAUDRATE == 500) //AHB1 主频60M / 500
{
can_parameter.prescaler = 12;
}
/* 250KBps */
else if (CAN_BAUDRATE == 250) //AHB1 主频60M / 250
{
can_parameter.prescaler = 24;
}
/* 125KBps */
else if (CAN_BAUDRATE == 125) //AHB1 主频60M / (SJW+BS1+BS2)/ prescaler
{
can_parameter.prescaler = 48;
}
/* 100KBps */
else if (CAN_BAUDRATE == 100) //AHB1 主频60M / 100
{
can_parameter.prescaler = 60;
}
/* 50KBps */
else if (CAN_BAUDRATE == 50)
{
can_parameter.prescaler = 120;
}
/* 20KBps */
else if (CAN_BAUDRATE == 20)
{
can_parameter.prescaler = 300;
}
/* initialize CAN */
can_init(CAN0, &can_parameter);
/* initialize filter */
can_filter.filter_number = 0;
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_FIFO1;
can_filter.filter_enable = ENABLE;
can_filter_init(&can_filter);
} |