Hello, I want to CAN0 of S32146 in CAN-FD mode. Initially I am using CAN0 as CAN 2.0 and working fine. But when I am using code in S32146, getting stuff error. I just modified the .fd enable, . payload and .data_length. Below is the code
status_t host_can_init(void)
{
status_t ret = STATUS_SUCCESS;
flexcan_user_config_t can_500kbps_init_cfg =
{
.fd_enable =true,
.pe_clock = FLEXCAN_CLK_SOURCE_PERIPH,
.max_num_mb = 4, //8,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = false,
.flexcanMode = FLEXCAN_NORMAL_MODE,
.payload = FLEXCAN_PAYLOAD_SIZE_64 , //FLEXCAN_PAYLOAD_SIZE_8,
.bitrate = {
.propSeg = 3U,
.phaseSeg1 = 10U,
.phaseSeg2 = 7U,
.preDivider = 9U,
.rJumpwidth = 1U
},
.bitrate_cbt = {
.propSeg = 3U,
.phaseSeg1 = 10U,
.phaseSeg2 = 7U,
.preDivider = 9U,
.rJumpwidth = 1U
},
/*
.bitrate = {
.propSeg = 3U,
.phaseSeg1 = 1U,
.phaseSeg2 = 2U,
.preDivider = 3U,
.rJumpwidth = 1U
},
.bitrate_cbt = {
.propSeg = 3U,
.phaseSeg1 = 1U,
.phaseSeg2 = 2U,
.preDivider = 3U,
.rJumpwidth = 1U
},
*/
.transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
.rxFifoDMAChannel = 0,
};
FLEXCAN_DRV_Deinit(HOST_CAN_INST);
/* CAN interface initialization */
ret = FLEXCAN_DRV_Init(HOST_CAN_INST, &host_can_state, &can_500kbps_init_cfg);
return ret;
}
void can_if_init_host (void)
{
flexcan_data_info_t data_info =
{
.data_length = 64U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.fd_enable = true,
.enable_brs = false,
.fd_padding = 0U
};
DEV_ASSERT(FLEXCAN_DRV_ConfigRxMb(HOST_CAN_INST, HOST_RX_MBX, &data_info, RX_HOST_MSG_ID) == STATUS_SUCCESS );
FLEXCAN_DRV_SetRxMbGlobalMask(HOST_CAN_INST, FLEXCAN_MSG_ID_STD, RX_HOST_MSG_ID);
DEV_ASSERT(FLEXCAN_DRV_SetRxIndividualMask(HOST_CAN_INST, FLEXCAN_MSG_ID_STD, HOST_RX_MBX, RX_HOST_MSG_ID) == STATUS_SUCCESS );
}
status_t can_send(uint8_t instance, uint8_t mb_idx, uint8_t *tx_data, uint32_t len, uint32_t msg_id, flexcan_msgbuff_id_type_t id_type)
{
status_t send_status = STATUS_SUCCESS;
//bool sucess = false;
flexcan_data_info_t txdata_info =
{
.data_length = len,
.msg_id_type = id_type,
.enable_brs = false,
.fd_enable = false,
.fd_padding = 0U,
.is_remote = false
};
if(instance == HOST_CAN_INST){
txdata_info.fd_enable = true;
}
if( FLEXCAN_DRV_GetTransferStatus(instance, mb_idx) != STATUS_BUSY ){
/* Configure TX message buffer with index TX_MBX and msg_id*/
FLEXCAN_DRV_ConfigTxMb(instance, mb_idx, &txdata_info, msg_id);
/* Start transimitting data */
send_status = FLEXCAN_DRV_Send(instance, mb_idx, &txdata_info, msg_id, tx_data);
}
return send_status;
}
Updated CAN bit rate configuration as below, still similar issue
.bitrate = {
.propSeg = 4U,
.phaseSeg1 = 7U,
.phaseSeg2 = 1U,
.preDivider = 9U,
.rJumpwidth = 1U
},
.bitrate_cbt = {
.propSeg = 4U,
.phaseSeg1 = 7U,
.phaseSeg2 = 1U,
.preDivider = 9U,
.rJumpwidth = 1U
},
If possible, please provide the entire project and I will test it for you.
the bitrate configuration is not right from your description.
have a try below setting
and i didn't find any more issues in the picture you provided.
if still have issues,please provided the demo code,
@Senlent I tried but still same issue.
status_t host_can_init(void)
{
status_t ret = STATUS_SUCCESS;
/* Configuration for 500kbps CAN bit rate */
flexcan_user_config_t can_500kbps_init_cfg =
{
.fd_enable =true,
.pe_clock = FLEXCAN_CLK_SOURCE_PERIPH,
.max_num_mb = 4, //8,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = false,
.flexcanMode = FLEXCAN_NORMAL_MODE,
.payload = FLEXCAN_PAYLOAD_SIZE_64 , //FLEXCAN_PAYLOAD_SIZE_8,
.bitrate = {
.propSeg = 7U,
.phaseSeg1 = 4U,
.phaseSeg2 = 1U,
.preDivider = 9U,
.rJumpwidth = 1U
},
.bitrate_cbt = {
.propSeg = 7U,
.phaseSeg1 = 4U,
.phaseSeg2 = 1U,
.preDivider = 9U,
.rJumpwidth = 1U
},
.transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
.rxFifoDMAChannel = 0,
};
/* CAN interface initialization */
ret = FLEXCAN_DRV_Init(HOST_CAN_INST, &host_can_state, &can_500kbps_init_cfg);
DEV_ASSERT(ret == STATUS_SUCCESS);
return ret;
}
void can_if_init_host (void)
{
flexcan_data_info_t data_info =
{
.data_length = 64U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.fd_enable = true,
.enable_brs = false,
.fd_padding = 0U
};
DEV_ASSERT(FLEXCAN_DRV_ConfigRxMb(HOST_CAN_INST, HOST_RX_MBX, &data_info, RX_HOST_MSG_ID) == STATUS_SUCCESS );
FLEXCAN_DRV_SetRxMbGlobalMask(HOST_CAN_INST, FLEXCAN_MSG_ID_STD, RX_HOST_MSG_ID);
DEV_ASSERT(FLEXCAN_DRV_SetRxIndividualMask(HOST_CAN_INST, FLEXCAN_MSG_ID_STD, HOST_RX_MBX, RX_HOST_MSG_ID) == STATUS_SUCCESS );
}
I checked with custom python script to receive the data, able to get data but it is in the multiple of 4, like if I send 13, receiving 16 bytes.