汇集网友智慧,解决技术难题
TI 脉冲 直接 MM GD32C103 CAN
赞0
评论
2024-07-05
2024-06-03
2024-06-02
点击图片添加到编辑器内容中
点击文件名将附件添加到文章中
提交
tyw
315个答案
天意无罪
284个答案
xch
206个答案
jjjyufan
197个答案
coody
187个答案
LcwSwust
146个答案
chunyang
135个答案
tpgf
110个答案
赞0
https://bbs.21ic.com/icview-3381510-1-1.html
评论
2024-07-05
赞0
评论
2024-06-03
赞0
gpio_pin_remap_config(GPIO_CAN1_REMAP, DISABLE);
评论
2024-06-02
赞0
can_trasnmit_message_struct txMsg = {
.tx_sfid = 0x00,
.tx_efid = 0x00,
.tx_ft = CAN_FT_DATA,
.tx_ff = CAN_FF_EXTENDED,
.tx_dlen = 0,
.fd_flag = 1,
.fd_brs = 0,
.fd_esi = 1
};
CAN1的初始化
void BSP_CAN_Init(void)
{
rcu_periph_clock_enable(RCU_CAN1);
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_12);
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);
//gpio_pin_remap_config(GPIO_CAN1_REMAP, ENABLE);
can_parameter_struct can_parameter;
can_fdframe_struct can_fd_parameter;
can_fd_tdc_struct can_fd_tdc_parameter;
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
can_deinit(CAN1);
/* initialize CAN parameters */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = DISABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.auto_retrans = DISABLE;
can_parameter.rec_fifo_overwrite = ENABLE;
can_parameter.trans_fifo_order = ENABLE;
can_parameter.working_mode = CAN_NORMAL_MODE;
can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
can_parameter.time_segment_1 = CAN_BT_BS1_7TQ;
can_parameter.time_segment_2 = CAN_BT_BS2_2TQ;
can_parameter.prescaler = 6;
can_init(CANX, &can_parameter);
can_struct_para_init(CAN_FD_FRAME_STRUCT, &can_fd_parameter);
can_fd_parameter.fd_frame = ENABLE;
can_fd_parameter.excp_event_detect = ENABLE;
can_fd_parameter.delay_compensation = ENABLE;
can_fd_tdc_parameter.tdc_filter = 0x04;
can_fd_tdc_parameter.tdc_mode = CAN_TDCMOD_CALC_AND_OFFSET;
can_fd_tdc_parameter.tdc_offset = 0x04;
can_fd_parameter.p_delay_compensation = &can_fd_tdc_parameter;
can_fd_parameter.iso_bosch = CAN_FDMOD_ISO;
can_fd_parameter.esi_mode = CAN_ESIMOD_HARDWARE;
/* FD mode data baudrate 2Mbps, sample piont at 80% */
can_fd_parameter.data_resync_jump_width = CAN_BT_SJW_1TQ;
can_fd_parameter.data_time_segment_1 = CAN_BT_BS1_3TQ;
can_fd_parameter.data_time_segment_2 = CAN_BT_BS2_1TQ;
/* CAN-FD data segement prescaler should be the same as non-data segement prescaler */
can_fd_parameter.data_prescaler = 6;
can_fd_init(CANX, &can_fd_parameter);
can1_filter_start_bank(14);
can_filter_mask_mode_init(0xaabb, 0x0000, CAN_EXTENDED_FIFO0, 15);
nvic_irq_enable(CAN1_RX0_IRQn, 1, 0);
can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0);
}
从队列取数据发送
void BSP_CAN_Background(void)
{
if(!util_FIFO_Any(&tx_fifo))
{
return;
}
const uint32_t available = CAN_TSTAT_TME0 | CAN_TSTAT_TME1 | CAN_TSTAT_TME2;
if((CAN_TSTAT(CANX) & available) == 0)
{
return;
}
FIFO_Index_t idx = util_FIFO_Out(&tx_fifo);
CAN_DataPacket_t *thisMsg = &tx_queue[idx];
txMsg.tx_efid = thisMsg->ExtID;
txMsg.tx_sfid = thisMsg->ExtID;
txMsg.tx_dlen = thisMsg->Len;
memcpy(txMsg.tx_data, &thisMsg->Data, thisMsg->Len);
can_message_transmit(CANX,&txMsg);
}
GPIO时钟再进行CAN初始化之前已经全部打开,中断分组也配置了
评论
2024-06-02
您需要登录后才可以回复 登录 | 注册