Hello,
We need to use two CAN interfaces on our board, so we need to use both CAN and CANFD. And now I have some trouble in using CANFD send data with changeable MsgId in the Classic CAN Mode.The code modification:
int32_t MCAN_Init(SOC_Handle socHandle)
{
int32_t errCode;
int32_t retVal = 0;
/* Configure the divide value for MCAN source clock */
SOC_setPeripheralClock(socHandle, SOC_MODULE_MCAN, SOC_CLKSOURCE_VCLK, 4U, &errCode);
#define Pinmux_SetFunc(pin, func) \
do { \
Pinmux_Set_OverrideCtrl(pin, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); \
Pinmux_Set_FuncSel(pin, func); \
} while (0)
/* Setup the PINMUX to bring out the XWR16xx CAN pins */
Pinmux_SetFunc(SOC_XWR16XX_PIND14_PADBN, SOC_XWR16XX_PIND14_PADBN_CANFD_TX);
Pinmux_SetFunc(SOC_XWR16XX_PINB14_PADBO, SOC_XWR16XX_PINB14_PADBO_CANFD_RX);
CANFD_MCANInitParams mcanCfgParams;
CANFD_MCANBitTimingParams mcanBitTimingParams;
MCAN_InitParams(&mcanCfgParams);
/* Initialize the CANFD driver */
canFdHandle = CANFD_init(&mcanCfgParams, &errCode);
if (canFdHandle == NULL)
{
System_printf ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
return -1;
}
MCAN_CalcBitTimeParams(&mcanBitTimingParams);
/* Configure the CAN driver */
retVal = CANFD_configBitTime (canFdHandle, &mcanBitTimingParams, &errCode);
if (retVal < 0)
{
System_printf ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
return -1;
}
/* Setup the transmit message object */
appMcanTxTarCfgParams.direction = CANFD_Direction_TX;
appMcanTxTarCfgParams.msgIdType = CANFD_MCANXidType_11_BIT; //11bit为标准帧 2018.12.18
appMcanTxTarCfgParams.msgIdentifier = DCAN_IDMin;
txTarMsgObjHandle = CANFD_createMsgObject (canFdHandle, &appMcanTxTarCfgParams, &errCode);
if (txTarMsgObjHandle == NULL)
{
System_printf ("Error: CANFD create Tx message object failed [Error code %d]\n", errCode);
return -1;
}
return 0;
}
int32_t MCAN_SendData(uint32_t id, unsigned char *buf,uint32_t datalen)
{
// int32_t i;
int32_t index = 0;
int32_t retVal = 0;
int32_t errCode = 0;
uint32_t MsgId = appMcanTxTarCfgParams.msgIdentifier;
CANFD_OptionTLV optionTLV;
CANFD_MCANMsgObjectStats msgObjStats;
Task_sleep(1);
if(datalen>=8)
{
retVal = CANFD_transmitData (txTarMsgObjHandle, MsgId, CANFD_MCANFrameType_CLASSIC, 8U, &buf[index], &errCode);
if(retVal)
{
System_printf ("Error: Transmit data failed [Error code %d]\n", errCode);
return -1;
}
datalen = datalen - 8;
index = index + 8;
MsgId = MsgId + 1;
Task_sleep(1);
}
optionTLV.type = CANFD_Option_MCAN_PROTOCOL_STATUS;
optionTLV.length = sizeof(CANFD_MCANMsgObjectStats);
optionTLV.value = (void*) &msgObjStats;
retVal = CANFD_getOptions(canFdHandle, &optionTLV, &errCode);
if (retVal < 0)
{
System_printf ("Error: CANFD get stats failed [Error code %d]\n", errCode);
return -1;
}
return 0;
}
I debug with CCS and it printf "Error: CANFD get stats failed [Error code -3501]". I tried to change the mcanCfgParams and data bit rate and it didn't work. Could you give me some help to solve this problem?Is there some configurations different between Classic Mode and FD Mode in the CANFD interface?
Thank you a lot,
Cassie