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.

TMS570LC4357: How to change DLC when sending

Part Number: TMS570LC4357

Dear team:

My customer want to know how to change DLC when sending message with DCAN module.

He had modified the DLC value in the canTransmit function, but it still failed.

He wants to know if there is a reference process. He has read the TRM many times but still doesn't understand it.

Best regards

Green

  • Hi Green,

    You can update the DLC before transmitting data from IFx register to DCAN message RAM or mailbox. The HAL code doesn't have a API to update the DLC, but you can write your own API. For example:

    void canUpdateDLC(canBASE_t *node, uint32 messageBox, uint8 msgBoxDLC)
    {

           /** - Wait until IF2 is ready for use */
          while ((node->IF2STAT & 0x80U) ==0x80U)
          {
          } /* Wait */

          node->IF2CMD = 0x90U;

          node->IF2MCTL &= ~(uint32)(0xFU);

          node->IF2MCTL |= (uint32)(msgBoxDLC & 0xFU);

          node->IF2NO = (uint8) messageBox;

          /** - Wait until data are copied into IF2 */
          while ((node->IF2STAT & 0x80U) ==0x80U)
          {
          } /* Wait */

    }

    The Data Length Code of a message object must be defined to the same value as in the corresponding objects with the same identifier at other nodes.

  • Hi QJ:

    1, Can we put this program into Transmit function?

    uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data,uint8 msgBoxDLC)
    {
    uint32 i;
    uint32 success = 0U;
    uint32 regIndex = (messageBox - 1U) >> 5U;
    uint32 bitIndex = 1U << ((messageBox - 1U) & 0x1FU);


    /* USER CODE BEGIN (7) */ //Add here

    /** - Wait until IF2 is ready for use */
    while ((node->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */

    node->IF2CMD = 0x90U;

    node->IF2MCTL &= ~(uint32)(0xFU);

    node->IF2MCTL |= (uint32)(msgBoxDLC & 0xFU);

    node->IF2NO = (uint8) messageBox;

    /** - Wait until data are copied into IF2 */
    while ((node->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */

    /* USER CODE END */

    /** - Check for pending message:
    * - pending message, return 0
    * - no pending message, start new transmission
    */

    if ((node->TXRQx[regIndex] & bitIndex) != 0U)
    {
    success = 0U;
    }

    else
    {
    /** - Wait until IF1 is ready for use */
    /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */
    while ((node->IF1STAT & 0x80U) ==0x80U)
    {
    } /* Wait */

    /** - Configure IF1 for
    * - Message direction - Write
    * - Data Update
    * - Start Transmission
    */
    /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */


    /** - Copy TX data into IF1 */
    for (i = 0U; i < msgBoxDLC; i++) //Change the cycle condition here to DLC
    {
    #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
    /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
    node->IF1DATx[i] = *data;
    /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
    data++;
    #else
    /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
    node->IF1DATx[s_canByteOrder[i]] = *data;
    /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
    data++;
    #endif
    }

    /** - Copy TX data into message box */
    /*SAFETYMCUSW 93 S MR: 6.1,6.2,10.1,10.2,10.3,10.4 <APPROVED> "LDRA Tool issue" */
    node->IF1NO = (uint8) messageBox;

    success = 1U;
    }
    /** @note The function canInit has to be called before this function can be used.\n
    * The user is responsible to initialize the message box.
    */

    /* USER CODE BEGIN (8) */
    /* USER CODE END */

    return success;
    }

    2, how to read DLC in the received message?

    Best regards

  • Can we put this program into Transmit function?

    Yes, you can add new ID, DLC to the transmit API.

    /** - Copy TX data into IF1 */
    for (i = 0U; i < msgBoxDLC; i++) //Change the cycle condition here to DLC
    {

    You don't have to change 8 to msgBoxDLC. Eight bytes data is transferred from IFx data registers (A and B) to Message RAM regardless how small the DLC is.

    how to read DLC in the received message?

    The DLC is part of message control register. You need to set CONTROL bit of CMD register and CLEAR W/R bit of CMD register for transferring DLC from Message RAM to Fx register:

    canGetData(0 API include this portion:

    /** - Configure IF2 for
    * - Message direction - Read
    * - Data Read
    * - Clears NewDat bit in the message object.
    */
    node->IF2CMD = 0x17U;

    /** - Copy data into IF2 */
    /*SAFETYMCUSW 93 S MR: 6.1,6.2,10.1,10.2,10.3,10.4 <APPROVED> "LDRA Tool issue" */
    node->IF2NO = (uint8) messageBox;

    /** - Wait until data are copied into IF2 */
    /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */
    while ((node->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */

    /** - Get number of received bytes */
    size = node->IF2MCTL & 0xFU;
    if(size > 0x8U)
    {
    size = 0x8U;
    }
    /** - Copy RX data into destination buffer */