我的CAN传输代码如下:在正常初始化以及赋值给了 appDcanTxData数据之后,运行时在下面绿色函数内发生异常
int32_t Can_Transmit_Schedule(uint8_t *txmsg,
uint32_t len)
{
volatile uint32_t index = 0;
int32_t retVal = 0;
int32_t errCode = 0;
CAN_DCANData appDcanTxData;
int32_t x = 0;
// System_printf ("MEssage %x len %d\n", msg_id, len);
Task_sleep(1);
while (len > 8U)
{
appDcanTxData.dataLength = 8U;
memcpy(appDcanTxData.msgData, &txmsg[index], 8U);
retVal = CAN_transmitData(txMsgObjHandle, &appDcanTxData, &errCode);
if (retVal < 0)
{
continue;
}
index = index + 8U;
len = len - 8U;
x++;
}
if (len > 0)
{
appDcanTxData.dataLength = len;
memcpy(appDcanTxData.msgData, &txmsg[index], len);
retVal = CAN_transmitData(txMsgObjHandle, &appDcanTxData, &errCode);
while (retVal < 0)
{
// System_printf("Debug: Error transmitting CAN data %x , Errcode %x\n", retVal, errCode);
retVal = CAN_transmitData(txMsgObjHandle, &appDcanTxData, &errCode);
}
}
return retVal;
}
函数在执行完上述红框内容后就跳出,数据传输不成功,但我并未发现有初始化不成功导致handle为null的情况,并且我成功给appDcanTxData结构体赋值,也不为null,问题出在哪里?