在车环境下,GD32E503进行CAN发送数据,出现偶然失败的问题,在周立功USBCAN-II+上并没有检测到发出来的数据,但can_transmit_states(CAN1, mbox)返回的结果是CAN_TRANSMIT_OK。在周立功USBCAN-II+模拟环境下,不会出现失败的问题,每次发都能检测到发出来的数据。请问有人知道实车环境下CAN数据偶然发送失败原因吗?
以下是初始化的代码:
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
can_deinit(CAN1);
/* initialize CAN */
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;
/* baudrate 1Mbps = 90M/ 6 / (5+3+1) */
tbs1 = CAN_BT_BS1_6TQ;
tbs2 = CAN_BT_BS2_3TQ;
brp = 18;
can_parameter.time_segment_1 = tbs1;
can_parameter.time_segment_2 = tbs2;
can_parameter.prescaler = brp;
can_init(CAN1, &can_parameter);
nvic_irq_enable(CAN1_RX0_IRQn, CAN1_PRIORITY, CAN1_SUBPRIORITY);
can_interrupt_enable(CAN1, CAN_INTEN_RFNEIE0);
以下是设置滤波器的代码:
void bsp_can_set_filter(can_port_t Port, uint16_t number, uint32_t datatype, uint32_t rxfid, uint32_t filtermask)
{
can_filter_parameter_struct can_filter;
if (Port == CAN_PORT_0) can_filter.filter_number = number;
else can_filter.filter_number = number + 14;
can_filter.filter_mode = CAN_FILTERMODE_MASK;
can_filter.filter_bits = CAN_FILTERBITS_32BIT;
if (datatype == CAN_FF_STANDARD) {
can_filter.filter_list_high = ((rxfid << 21) & 0xffff0000) >> 16;
can_filter.filter_list_low = ((rxfid << 21) | datatype | CAN_FT_DATA) & 0xffff;
} else {
can_filter.filter_list_high = ((rxfid << 3) & 0xffff0000) >> 16;
can_filter.filter_list_low = ((rxfid << 3) | datatype | CAN_FT_DATA) & 0xffff;
}
if (datatype == CAN_FF_STANDARD) {
can_filter.filter_mask_high = ((filtermask << 21) & 0xffff0000) >> 16;
can_filter.filter_mask_low = ((filtermask << 21) | datatype | CAN_FT_DATA) & 0xffff;
} else {
can_filter.filter_mask_high = ((filtermask << 3) & 0xffff0000) >> 16;
can_filter.filter_mask_low = ((filtermask << 3) | datatype | CAN_FT_DATA) & 0xffff;
}
can_filter.filter_fifo_number = CAN_FIFO0;
can_filter.filter_enable = ENABLE;
can_filter_init(CAN0, &can_filter);
} |