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.

[参考译文] TMS320F28388D:是否可以发送具有不同 ID 和配置了单个邮箱的 CAN 帧?

Guru**** 2541140 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1324811/tms320f28388d-is-it-possible-to-send-can-frames-with-different-ids-with-a-single-mailbox-configured

器件型号:TMS320F28388D

您好!

我将一个单一邮箱声明为输出(使用它的扩展模式 TXIE):  

其中 id_BASE =帧 ID:0x18FF50E5和 SC_CAN_NUMMAILBOX_TX = num 邮箱:1

然后我想通过相同的 num Mailbox 发送两个连续的帧、但帧 ID 不同:第一个 ID = 0x18FF50E5、第二个 ID 为0x18FF51E5。

两个帧具有相同的 ID:

我想使用 can_sendMessage_updateDLC 函数、因为这两个帧具有两个不同的 DLC。

我试图用这个函数制作我自己的函数:can_sendMessage_updateMsgIdMsgDLC 来添加标识符作为参数、并将其写入 CAN_IF1ARB 寄存器:  

ID 具有所需的地址:0x18FF51E5、但帧实际上输出保留了插入的初始地址 Viia CAN_setupMessageObject

那么、是否可以传输具有不同 ID 并将单个邮箱配置为输出的 CAN 帧?

感谢你的帮助。

埃里克

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Eric、  

    我们明天会回来与您讨论这方面的内容。  

    谢谢。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Sahi:

    好的、我在等待您的反馈。

    此致、

    埃里克

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Eric、  

    我试图用这个来制作我自己的函数:can_sendMessage_updateMsgIdMsgDLC 添加标识符作为参数,将其写入 CAN_IF1ARB 寄存器

    写入任一消息目标的过程包括更新仲裁寄存器、然后在 Dir 位被设定为1时写入命令寄存器(CAN_IF1CMD)。  

    [quote userid="586839" url="~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1324811/tms320f28388d-is-it-possible-to-send-can-frames-with-different-ids-with-a-single-mailbox-configured 这样、是否可以在将单一邮箱配置为输出的情况下传输具有不同 ID 的 CAN 帧?

    这是可能的。 我可以在2月21日星期三之前为您提供一个经过验证的功能。  

    谢谢。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、Sahil:

    感谢您的答复。

    写入任何消息对象的过程包括更新仲裁寄存器,然后写入命令寄存器(CAN_IF1CMD),Dir 位设置为1。  [/报价]

    在我看来、这似乎是我正在做的、但可能很糟糕:   

    static void CAN_sendMessage_updateMsgIdMsgDLC(uint32_t base, uint32_t objID,
                                                  SC_CAN_frame_type_t msgType, uint32_t msgID,
                                                  uint16_t msgLen, const uint8_t *msgData)
    {
        uint32_t arbReg = 0U;
        uint32_t msgCtrl = 0U;
    
        //
        // Check the arguments.
        //
        ASSERT(CAN_isBaseValid(base));
        ASSERT((objID <= 32U) && (objID > 0U));
        ASSERT(msgLen <= 8U);
    
        //
        // Set IF command to read message object control value
        //
        // Set up the request for data from the message object.
        // Transfer the message object to the IF register.
        //
        HWREG_BP(base + CAN_O_IF1CMD) = ((uint32_t)CAN_IF1CMD_CONTROL |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Read IF message control
        //
        msgCtrl = HWREGH(base + CAN_O_IF1MCTL);
    
        //------
        // Modif EF add "ID"
        //-----
        
        arbReg = CAN_IF1ARB_DIR; // Sens Tx
        //
        // Set values based on Extended Frame or Standard Frame
        //
        if(msgType == SC_CAN_FRAME_TYPE_DATA_EXT)
        {
            //
            // Set the 29 bit version of the Identifier for this message
            // object. Mark the message as valid and set the extended ID bit.
            //
            arbReg |= (msgID & CAN_IF1ARB_ID_M) | CAN_IF1ARB_MSGVAL |
                      CAN_IF1ARB_XTD;
        }
        else
        {
            //
            // Set the 11 bit version of the Identifier for this message
            // object. The lower 18 bits are set to zero. Mark the message as
            // valid.
            //
            arbReg |= ((msgID << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M) |
                      CAN_IF1ARB_MSGVAL;
        }
        HWREG_BP(base + CAN_O_IF1ARB) = arbReg;
        // End Modif EF of add "ID"
        //-----
    
        //
        // Update to the new data length
        //
        msgCtrl &= ~CAN_IF1MCTL_DLC_M;
        msgCtrl |= (msgLen & CAN_IF1MCTL_DLC_M);
    
        //
        // Write out to the register to program the message object
        //
        HWREG_BP(base + CAN_O_IF1MCTL) = msgCtrl;
    
        //
        // Transfer data to message object RAM
        //
        HWREG_BP(base + CAN_O_IF1CMD) =
            (CAN_IF1CMD_CONTROL | CAN_IF1CMD_DIR | (objID & CAN_IF1CMD_MSG_NUM_M));
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Set IF command to read message object control value
        //
        // Set up the request for data from the message object.
        // Transfer the message object to the IF register.
        //
        HWREG_BP(base + CAN_O_IF1CMD) = ((uint32_t)CAN_IF1CMD_CONTROL |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Read IF message control
        //
        msgCtrl = HWREGH(base + CAN_O_IF1MCTL);
    
        //
        // Check provided DLC size with actual Message DLC size
        //
        ASSERT((msgCtrl & CAN_IF1MCTL_DLC_M) == msgLen);
    
        //
        // Write the data out to the CAN Data registers.
        //
        CAN_writeDataReg(msgData, (base + CAN_O_IF1DATA),
                         (msgCtrl & CAN_IF1MCTL_DLC_M));
    
        //
        //  Set Data to be transferred from IF
        //
        if(msgLen > 0U)
        {
            msgCtrl = CAN_IF1CMD_DATA_B | CAN_IF1CMD_DATA_A;
        }
        else
        {
            msgCtrl = 0U;
        }
    
        //
        // Set Direction to write
        //
        // Set Tx Request Bit
        //
        // Transfer the message object to the message object specified by
        // objID.
        //
    
        HWREG_BP(base + CAN_O_IF1CMD) = (msgCtrl | (uint32_t)CAN_IF1CMD_DIR |
                                         (uint32_t)CAN_IF1CMD_TXRQST |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    }
    

    好的、要在21日星期三收到您的函数、谢谢。

    此致、

    埃里克  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Eric、  

    我修改了您的函数并能够对其进行验证。  

    static void CAN_sendMessage_updateMsgIdMsgDLC(uint32_t base, uint32_t objID,
                                                  SC_CAN_frame_type_t msgType, uint32_t msgID,
                                                  uint16_t msgLen, const uint8_t *msgData)
    {
        uint32_t arbReg = 0U;
        uint32_t msgCtrl = 0U;
    
        //
        // Check the arguments.
        //
        ASSERT(CAN_isBaseValid(base));
        ASSERT((objID <= 32U) && (objID > 0U));
        ASSERT(msgLen <= 8U);
    
        //
        // Set IF command to read message object control value
        //
        // Set up the request for data from the message object.
        // Transfer the message object to the IF register.
        //
        HWREG_BP(base + CAN_O_IF1CMD) = ((uint32_t)CAN_IF1CMD_CONTROL |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Read IF message control
        //
        msgCtrl = HWREGH(base + CAN_O_IF1MCTL);
    
        //------
        // Modif EF add "ID"
        //-----
        
        arbReg = CAN_IF1ARB_DIR; // Sens Tx
        //
        // Set values based on Extended Frame or Standard Frame
        //
        if(msgType == SC_CAN_FRAME_TYPE_DATA_EXT)
        {
            //
            // Set the 29 bit version of the Identifier for this message
            // object. Mark the message as valid and set the extended ID bit.
            //
            arbReg |= (msgID & CAN_IF1ARB_ID_M) | CAN_IF1ARB_MSGVAL |
                      CAN_IF1ARB_XTD;
        }
        else
        {
            //
            // Set the 11 bit version of the Identifier for this message
            // object. The lower 18 bits are set to zero. Mark the message as
            // valid.
            //
            arbReg |= ((msgID << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M) |
                      CAN_IF1ARB_MSGVAL;
        }
        HWREG_BP(base + CAN_O_IF1ARB) = arbReg;
        // End Modif EF of add "ID"
        //-----
    
        //
        // Update to the new data length
        //
        msgCtrl &= ~CAN_IF1MCTL_DLC_M;
        msgCtrl |= (msgLen & CAN_IF1MCTL_DLC_M);
    
        //
        // Write out to the register to program the message object
        //
        HWREG_BP(base + CAN_O_IF1MCTL) = msgCtrl;
    
        //
        // Transfer data to message object RAM
        //
        HWREG_BP(base + CAN_O_IF1CMD) =
            (CAN_IF1CMD_CONTROL | CAN_IF1CMD_DIR | CAN_IF1CMD_ARB | (objID & CAN_IF1CMD_MSG_NUM_M));                // Set bit to transfer arbitration bits to message object
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Set IF command to read message object control value
        //
        // Set up the request for data from the message object.
        // Transfer the message object to the IF register.
        //
        HWREG_BP(base + CAN_O_IF1CMD) = ((uint32_t)CAN_IF1CMD_CONTROL |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    
        //
        // Wait for busy bit to clear
        //
        while((HWREGH(base + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) == CAN_IF1CMD_BUSY)
        {
        }
    
        //
        // Read IF message control
        //
        msgCtrl = HWREGH(base + CAN_O_IF1MCTL);
    
        //
        // Check provided DLC size with actual Message DLC size
        //
        ASSERT((msgCtrl & CAN_IF1MCTL_DLC_M) == msgLen);
    
        //
        // Write the data out to the CAN Data registers.
        //
        CAN_writeDataReg(msgData, (base + CAN_O_IF1DATA),
                         (msgCtrl & CAN_IF1MCTL_DLC_M));
    
        //
        //  Set Data to be transferred from IF
        //
        if(msgLen > 0U)
        {
            msgCtrl = CAN_IF1CMD_DATA_B | CAN_IF1CMD_DATA_A;
        }
        else
        {
            msgCtrl = 0U;
        }
    
        //
        // Set Direction to write
        //
        // Set Tx Request Bit
        //
        // Transfer the message object to the message object specified by
        // objID.
        //
    
        HWREG_BP(base + CAN_O_IF1CMD) = (msgCtrl | (uint32_t)CAN_IF1CMD_DIR |
                                         (uint32_t)CAN_IF1CMD_TXRQST |
                                         (objID & CAN_IF1CMD_MSG_NUM_M));
    }

    如果您在使用此函数时遇到任何问题、请告诉我。  

    谢谢。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、Sahil:

    非常感谢您的帮助、很抱歉这么晚才回复、我上周不在办公室。

    您的修改已更正我的问题!

    此致、

    埃里克