最近在使用E508在调试CAN通讯的时候根据V1.2.4的example配置CAN发送和接收时,CAN收发器使用的TJA1043
(1)使用CANFD盒收数据能够收到数据,使用USBCANI的CAN盒时无法收到;
(2)当修改波特率为500K的时候两个CAN盒都收不到了;
(3)在调试CAN中断接收时,配置为RX FIFO0 no empty进入中断时,单步调试在能够接收到的上位机界面发送数据的时候,上位机发送数据,接收中断无法接收到任何信息,不进入中断。
static void can_config(void)
{
can_parameter_struct can_parameter;
can_filter_parameter_struct can_filter;
can_struct_para_init(CAN_INIT_STRUCT, &can_parameter);
/* initialize CAN register */
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.auto_retrans = DISABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode = CAN_NORMAL_MODE;
/* baudrate 1Mbps, sample piont at 80% */
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 = 9U;
/* initialize CAN */
can_init(CAN0, &can_parameter);
nvic_irq_enable(CAN0_RX0_IRQn, 0U, 0U);
/* enable can receive FIFO0 not empty interrupt */
can_interrupt_enable(CAN0, CAN_INTEN_RFNEIE0);
can_interrupt_enable(CAN0, CAN_INT_WERR);
can_interrupt_enable(CAN0, CAN_INT_PERR);
can_interrupt_enable(CAN0, CAN_INT_BO);
can_interrupt_enable(CAN0, CAN_INT_ERRN);
can_interrupt_enable(CAN0, CAN_INT_ERR);
can_interrupt_enable(CAN0, CAN_INT_WAKEUP);
can_interrupt_enable(CAN0, CAN_INT_SLPW);
}
void can_tx_rx_mailbox_init(void)
{
can_tx_mailbox_init(0xaabb,CAN_FF_EXTENDED,CAN_FT_DATA,8,&gTransmit_message);
can_rx_mailbox_init(0x20,CAN_FF_STANDARD,CAN_FT_DATA,8,0,&receive_message);
}
void CAN0_RX0_IRQHandler(void)
{
if(SET==can_interrupt_flag_get(CAN0, CAN_INT_FLAG_RFL0))
{
can_message_receive(CAN0, CAN_FIFO0, &receive_message);
}
} |