My projects are based on Flexcan and ETHERNET.Now I'm going to re-initialize Flexcan after receiving the command over the network,but I can't restart FlexCan successfully.The driver isn't normal.CANFD communication is error.The log of CANFD sender, printf ErrorFrame.The code is as follows:
flexcan_user_config_t my_canCom1_InitConfig0 = {
.fd_enable = true,
.pe_clock = FLEXCAN_CLK_SOURCE_OSC,
.max_num_mb = 16,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = false,
.flexcanMode = FLEXCAN_NORMAL_MODE,
.payload = FLEXCAN_PAYLOAD_SIZE_64,
.bitrate = {
.propSeg = 7,
.phaseSeg1 = 5,
.phaseSeg2 = 4,
.preDivider = 1,
.rJumpwidth = 1
},
.bitrate_cbt = {
.propSeg = 11,
.phaseSeg1 = 3,
.phaseSeg2 = 3,
.preDivider = 0,
.rJumpwidth = 1
},
.transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
.rxFifoDMAChannel = 0U
};
flexcan_data_info_t dataInfo =
{
.data_length = 64U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
// .msg_id_type = FLEXCAN_MSG_ID_EXT,
.enable_brs = true,
.fd_enable = true,
.fd_padding = 0U
};
FLEXCAN_DRV_Deinit(INST_CANCOM1);
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1,my_callback_event,NULL);
/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, 0u);
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1,FLEXCAN_MSG_ID_STD,0);
If anyone can help to solve this problem?Thanks you very much!
Solved! Go to Solution.
Hi,
you can use FLEXCAN_DRV_SetBitrate and FLEXCAN_DRV_SetBitrateCbt for that, but changing bitrate requires all nodes on bus follow that too, otherwise you get error for further communications.
BR, Petr
Hi,
why is the deinit/init needed in fact? What kind of error is detected on sender side?
You can inspect FlexCAN module registers to know if Normal mode is entered and no errors are detected during message reception. Not sure if module also transmit anything.
BR, Petr
Because I wanted to send commands to the MCU over the network and then change the baud rate of its CANFD communication, I used DeInit and Init to change the CANFD baud rate.
Thanks for your advice. I'll try.
Hi,
you can use FLEXCAN_DRV_SetBitrate and FLEXCAN_DRV_SetBitrateCbt for that, but changing bitrate requires all nodes on bus follow that too, otherwise you get error for further communications.
BR, Petr
Your advice is very useful, thank you!!! \ ^_^ / \ ^_^ / \ ^_^ /