我在awr1642 demo的基础上添加了CAN总线,但发送数据失败,请大神指教!
void Can_Initialize(void)
{
int32_t errCode = 0;
int32_t retVal = 0;
// int32_t j = 0;
//CANFD_OptionTLV optionTLV;
CANFD_MCANInitParams mcanCfgParams;
CANFD_MCANBitTimingParams mcanBitTimingParams;
#if 0
CANFD_MCANMsgObjectStats msgObjStats;
CANFD_MCANErrCntStatus errCounter;
CANFD_MCANProtocolStatus protoStatus;
#endif
CANFD_MCANMsgObjCfgParams rxMsgObjectParams;
//CANFD_MsgObjHandle rxMsgObjHandle[2];
gTxDoneFlag = 0;
gRxDoneFlag = 0;
/* Setup the PINMUX to bring out the XWR16xx CAN pins */
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PINE14_PADAE, SOC_XWR16XX_PINE14_PADAE_CANFD_TX);
Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
Pinmux_Set_FuncSel(SOC_XWR16XX_PIND13_PADAD, SOC_XWR16XX_PIND13_PADAD_CANFD_RX);
/* Configure the divide value for MCAN source clock */
SOC_setPeripheralClock(gSrrMSSMCB.socHandle, SOC_MODULE_MCAN, SOC_CLKSOURCE_VCLK, 4U, &errCode);
/* Initialize peripheral memory */
SOC_initPeripheralRam(gSrrMSSMCB.socHandle, SOC_MODULE_MCAN, &errCode);
//CSL_FINSR(0x43201450, 22, 22, 0x1U);
//CSL_FINSR(0x4320140C, 26, 16, 0x23U);
MCANAppInitParams(&mcanCfgParams);
/* Initialize the CANFD driver */
canHandle = CANFD_init(&mcanCfgParams, &errCode);
if (canHandle == NULL)
{
System_printf ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
return ;
}
/* Configuring 1Mbps and 5Mbps as nominal and data bit-rate respectively
Prop seg: 8
Ph seg 1: 6
Ph Seg2 : 5
Sync jump: 1
BRP(Baud rate Prescaler): 2
Nominal Bit rate = (40)/(((8+6+5)+1)*BRP) = 1Mhz
Timing Params for Data Bit rate:
Prop seg: 2
Ph seg 1: 2
Ph Seg2 : 3
Sync jump: 1
BRP(Baud rate Prescaler): 1
Nominal Bit rate = (40)/(((2+2+3)+1)*BRP) = 5Mhz
*/
#if 1
mcanBitTimingParams.nomBrp = 0x2U;
mcanBitTimingParams.nomPropSeg = 0x8U;
mcanBitTimingParams.nomPseg1 = 0x6U;
mcanBitTimingParams.nomPseg2 = 0x5U;
mcanBitTimingParams.nomSjw = 0x1U;
#else
/*500Kbps NomBitRate: (40)/(((6+5+4)+1)*5)*/
mcanBitTimingParams.nomBrp = 0x5U;
mcanBitTimingParams.nomPropSeg = 0x6U;
mcanBitTimingParams.nomPseg1 = 0x5U;
mcanBitTimingParams.nomPseg2 = 0x4U;
mcanBitTimingParams.nomSjw = 0x1U;
#endif
#if 1 //5 Mbps
mcanBitTimingParams.dataBrp = 0x1U;
mcanBitTimingParams.dataPropSeg = 0x2U;
mcanBitTimingParams.dataPseg1 = 0x2U;
mcanBitTimingParams.dataPseg2 = 0x3U;
mcanBitTimingParams.dataSjw = 0x1U;
#else //2 Mbps
mcanBitTimingParams.dataBrp = 0x4U;
mcanBitTimingParams.dataPropSeg = 01U;
mcanBitTimingParams.dataPseg1 = 0x2U;
mcanBitTimingParams.dataPseg2 = 0x1U;
mcanBitTimingParams.dataSjw = 0x1U;
#endif
/* Configure the CAN driver */
retVal = CANFD_configBitTime(canHandle, &mcanBitTimingParams, &errCode);
if (retVal < 0)
{
System_printf ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
return ;
}
/* Setup the transmit message object */
txMsgObjectParams.direction = CANFD_Direction_TX;
txMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
txMsgObjectParams.msgIdentifier = 0xD1;
txMsgObjHandle = CANFD_createMsgObject (canHandle, &txMsgObjectParams, &errCode);
if (txMsgObjHandle == NULL)
{
System_printf ("Error: CANFD create Tx message object failed [Error code %d]\n", errCode);
return ;
}
/* Setup the receive message object */
rxMsgObjectParams.direction = CANFD_Direction_RX;
rxMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
rxMsgObjectParams.msgIdentifier = 0xD1;
rxMsgObjHandle = CANFD_createMsgObject(canHandle, &rxMsgObjectParams,
&errCode);
if (rxMsgObjHandle == NULL)
{
System_printf(
"Error: CANFD create Rx message object failed [Error code %d]\n",
errCode);
return;
}
}
Wesley He:
回复 Wesley He:
另外,CAN-FD管脚与板载SPI复用,需要检查是否有将CAN-FD的管脚引出?
指的是,是否有在EVM板上切换拨码开关选择或是使用电阻跳线。
user5921064:
回复 Wesley He:
我使用的是CAN-FD管脚,并且已经将拨码开关拨到了CAN-FD端。
user5921064:
回复 user5921064:
波特率也可以识别到,我用USB2CAN工具显示接收错误计数128,总线数据错误,错误报警,被动错误
Wesley He:
回复 user5921064:
请问你使用的是CAN-FD工具进行接收的吗?使用CAN-FD工具配合以下两篇文档中的示例代码,AWR1642发送,PC接收是测试过可行的。
CAN-FD是兼容普通CAN协议的。
可以查看一下这两份文档。
Adding CAN Tx and Rx to an Existing mmWave Project
http://www.ti.com/cn/lit/pdf/spracg9
CAN Node on AWR1642
http://www.ti.com/cn/lit/pdf/swra606
user5921064:
回复 Wesley He:
AWR1642应该使用的是CAN-FD,我就是按照你们的文档做的呀,但是没有DATA出来, 麻烦看下我的初始化有问题么
user5921064:
回复 Wesley He:
请教下SDK怎么编译呀
user5921064:
回复 user5921064:
调用CANFD_transmitData返回的errCode=-442503144