This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/AWR1443: MCAN to DCAN

Part Number: AWR1443
Other Parts Discussed in Thread: AWR1642,

Tool/software: TI C/C++ Compiler

Hi,

I am using awr1642 and awr1443 , trying to communicate using CAN .  I can transmit data from DCAN to MCAN. without loss and delay.

awr1443 DCAN is receiving and awr1642 MCAN is transmitting. 

While trying to transmit data from DCAN in 1443 to MCAN in awr1642,   

data is not being received properly. if it is one byte of data it is transmitted after some time.

if it is more than 1 byte of data, 

first one byte is receiving continuously some time, then remaining data is receiving continuously . this is repeating. 

    in DCAN , should i call DCAN_getData() function separately because callback function is not calling automatically.

 code is in awr1443 DCAN 

********************************************************************************************************************************

static int32_t dcanReceiveTest()
{
CAN_Handle canHandle;
CAN_MsgObjHandle txMsgObjHandle;
CAN_MsgObjHandle rxMsgObjHandle;
int32_t retVal = 0;
int32_t errCode = 0;

uint32_t i;

/* Initialize the DCAN parameters that need to be specified by the application */
DCANAppInitParams(&appDcanCfgParams,
&appDcanTxCfgParams,
&appDcanRxCfgParams,
&appDcanTxData);


/* Initialize the CAN driver */
canHandle = CAN_init(&appDcanCfgParams, &errCode);
if (canHandle == NULL)
{
System_printf ("Error: CAN Module Initialization failed [Error code %d]\n", errCode);
return -1;
}

/* Set the desired bit rate based on input clock */
retVal = DCANAppCalcBitTimeParams(DCAN_APP_INPUT_CLK / 1000000,
DCAN_APP_BIT_RATE / 1000,
DCAN_APP_SAMP_PT,
DCAN_APP_PROP_DELAY,
&appDcanBitTimeParams);
if (retVal < 0)
{
System_printf ("Error: CAN Module bit time parameters are incorrect \n");
return -1;
}

/* Configure the CAN driver */
retVal = CAN_configBitTime (canHandle, &appDcanBitTimeParams, &errCode);
if (retVal < 0)
{
System_printf ("Error: CAN Module configure bit time failed [Error code %d]\n", errCode);
return -1;
}

/* Setup the transmit message object */


txMsgObjHandle = CAN_createMsgObject (canHandle, DCAN_TX_MSG_OBJ, &appDcanTxCfgParams, &errCode);
if (txMsgObjHandle == NULL)
{
System_printf ("Error: CAN create Tx message object failed [Error code %d]\n", errCode);
return -1;
}

/* Setup the receive message object */
rxMsgObjHandle = CAN_createMsgObject (canHandle, DCAN_RX_MSG_OBJ, &appDcanRxCfgParams, &errCode);
if (rxMsgObjHandle == NULL)
{
System_printf ("Error: CAN create Rx message object failed [Error code %d]\n", errCode);
return -1;
}

while (1)
{



 ;
memset(appDcanRxData.msgData,'\0',8);

//  Task_sleep(1);
//System_printf("reveiced status is %d\n",flag);
retVal = CAN_getData (rxMsgObjHandle, &appDcanRxData, &errCode);


// if(flag == 1){
//Task_sleep(6);
// System_printf("data is %s\n",appDcanRxData.msgData);
//System_printf("received Data Length is %d\n",appDcanRxData.dataLength);


 for(i=0;i<appDcanRxData.dataLength;i++)
 System_printf("%c ",appDcanRxData.msgData[i]);
 System_printf("\n");

Task_sleep(15);
flag =0;
//}


iterationCount++;


}
}

****************************************************************************************************

code in MCAN is 

memcpy(txData,"vayatron",8);

 

while (1)
{
/* Send data over Tx message object */


length = 8U;;

index = 0;
msgId = txMsgObjectParams.msgIdentifier;
Task_sleep(1);
System_printf("Sending Data is %s\n",txData);
while(length > 8U)
{


retVal = CANFD_transmitData (txMsgObjHandle, msgId, CANFD_MCANFrameType_CLASSIC, 8U, &txData[index], &errCode);
// System_printf("dlc1 length is %d\n",datalen);
for(i=index;i<index+8;i++)
System_printf("%c ",txData[i]);
System_printf("\n");
length = length - 8U;
index = index + 8U;
// msgId = msgId + 1;
Task_sleep(1);
}

Task_sleep(3);

retVal = CANFD_transmitData (txMsgObjHandle, msgId, CANFD_MCANFrameType_CLASSIC, length, &txData[index], &errCode);


/* for(i=index;i<index+8;i++)
System_printf("%c ",txData[i]);
System_printf("\n");*/


System_printf("Receive status is %d\n",flag);

Task_sleep(4);
if (retVal < 0)
{
msgLstErrCnt++;
continue;
}

iterationCount++;

}

The bit setting values in DCAN are 

dcanCfgParams->parityEnable = 0;
dcanCfgParams->intrLine0Enable = 1;
dcanCfgParams->intrLine1Enable = 1;
dcanCfgParams->testModeEnable = 0;
dcanCfgParams->eccModeEnable = 0;
dcanCfgParams->stsChangeIntrEnable = 0;

dcanCfgParams->autoRetransmitDisable = 1;
dcanCfgParams->autoBusOnEnable = 0;
dcanCfgParams->errIntrEnable = 1;
dcanCfgParams->autoBusOnTimerVal = 0;
dcanCfgParams->if1DmaEnable = 0;
dcanCfgParams->if2DmaEnable = 0;
dcanCfgParams->if3DmaEnable = 0;
dcanCfgParams->ramAccessEnable = 0;
dcanCfgParams->appCallBack = DCANAppErrStatusCallback;

/*Intialize DCAN tx Config Params*/
dcanTxCfgParams->xIdFlagMask = 0x1;
dcanTxCfgParams->dirMask = 0x1;
dcanTxCfgParams->msgIdentifierMask = 0x1FFFFFFF;

dcanTxCfgParams->msgValid = 1;
dcanTxCfgParams->xIdFlag = CAN_DCANXidType_11_BIT;
dcanTxCfgParams->direction = CAN_Direction_TX;
dcanTxCfgParams->msgIdentifier = 0x11;

dcanTxCfgParams->uMaskUsed = 1;


dcanTxCfgParams->intEnable = 1;

dcanTxCfgParams->remoteEnable = 0;
dcanTxCfgParams->fifoEOBFlag = 1;
dcanTxCfgParams->appCallBack = DCANAppCallback;

/*Intialize DCAN Rx Config Params*/
dcanRxCfgParams->xIdFlagMask = 0x1;
dcanRxCfgParams->msgIdentifierMask = 0x1FFFFFFF;
dcanRxCfgParams->dirMask = 0x1;

dcanRxCfgParams->msgValid = 1;
dcanRxCfgParams->xIdFlag = CAN_DCANXidType_11_BIT;
dcanRxCfgParams->direction = CAN_Direction_RX;
dcanRxCfgParams->msgIdentifier = 0x24;

dcanRxCfgParams->uMaskUsed = 1;
dcanRxCfgParams->intEnable = 1;

dcanRxCfgParams->remoteEnable = 0;
dcanRxCfgParams->fifoEOBFlag = 1;
dcanRxCfgParams->appCallBack = DCANAppCallback;

I set a flag in callback when mode is Rx, if it is called I make it one there to check the receive status. 

call back calling once in 100 times. not calling properly in DCAN awr1443. I used only one System_printf function to display the data .

Please suggest me, if any changes should I do to  make it receive properly to DCAN from MCAN.  

Thanks and regards,

K Subrahmaniam

  • Hi Subramaniam,

    You will need to check if there are any pending TX message request before transmitting next message. Please check the below function. You will need to include this in your implmentation of both MCAN and DCAN.

    int32_t CAN_IsTransmitPending(CAN_MsgObjHandle handle, int32_t* errCode)
    {
    CAN_DriverMCB* ptrCanMCB;
    uint32_t baseAddr;
    int32_t retVal = 0;
    CAN_MessageObject* ptrCanMsgObj;

    ptrCanMsgObj = (CAN_MessageObject*)handle;
    if ((ptrCanMsgObj == NULL))
    {
    *errCode = CAN_EINVAL;
    retVal = MINUS_ONE;
    }
    /* Get the pointer to the CAN Driver Block */
    ptrCanMCB = (CAN_DriverMCB*)handle;
    if ((ptrCanMCB == NULL) )
    {
    *errCode = CAN_EINVAL;
    retVal = MINUS_ONE;

    }
    baseAddr = ptrCanMCB->hwCfg.regBaseAddress;
    retVal = DCANIsTxMsgPending( baseAddr, ptrCanMsgObj->msgObjectNum);

    return retVal;
    }

    BR,

    Raghu