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.

[参考译文] TMS320F280037:CAN 消息中断- RX 有效、TX 无效

Guru**** 1169120 points
Other Parts Discussed in Thread: TMS320F280037, C2000WARE
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1308590/tms320f280037-can-message-interrupts----rx-works-tx-not

器件型号:TMS320F280037
主题中讨论的其他器件: C2000WARE

大家好、

我现在使用 TMS320F280037电路板、并使用其 CAN 总线进行通信。  

在应用程序中、我在 main 中设置了多个 TX 和 RX 消息对象、例如  

CAN_initModule(CANA_BASE);

CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 20);

CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR |CAN_INT_STATUS);

...

Interrupt_register(INT_CANA0, &canaISR);
    
Interrupt_enable(INT_CANA0);
CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);

// TX message object, # 1
CAN_setupMessageObject(CANA_BASE, 1, 0x111,
                           CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
                           CAN_MSG_OBJ_TX_INT_ENABLE, 8);

// TX message object, # 2
CAN_setupMessageObject(CANA_BASE, 2, 0x112,
                           CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
                           CAN_MSG_OBJ_TX_INT_ENABLE, 8);

// RX message object, # 3
CAN_setupMessageObject(CANA_BASE, 3, 0x101,
                       CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, 0,
                       CAN_MSG_OBJ_RX_INT_ENABLE, 8);
                       
CAN_startModule(CANA_BASE);

在 canaISR 中、我定义了每个事件(传输和接收中断)发生时的操作、类似于

__interrupt void canaISR(void)
{
    uint32_t intr_status;
    uint32_t can_status;

    //
    // Read the CAN-B interrupt status to find the cause of the interrupt
    //
    intr_status = CAN_getInterruptCause(CANA_BASE);

    //
    // If the cause is a controller status interrupt, then get the status
    //
    switch (intr_status) {
    case CAN_INT_INT0ID_STATUS:
    {
        //
        // Read the controller status.  This will return a field of status
        // error bits that can indicate various errors.  Error processing
        // is not done in this example for simplicity.  Refer to the
        // API documentation for details about the error status bits.
        // The act of reading this status will clear the interrupt.
        //
        can_status = CAN_getStatus(CANA_BASE);

        break;
    }

    case 3: // the RX message object # (which is 3)
    {
        // ... application codes

        CAN_clearInterruptStatus(CANA_BASE, 3);

        break;
    }


    case 1: // TX message object: 1
    case 2: // TX message object: 2
    {
        // basically nothing to do here just clear the status
        CAN_clearInterruptStatus(CANA_BASE, intr_status);
        break;
    }

    default:
    {
        //
        // Spurious interrupt handling can go here.
        //
        break;
    }

    } // end-switch

    //
    // Clear the global interrupt flag for the CAN interrupt line
    //
    CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);

    //
    // Acknowledge this interrupt located in group 9
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}
/************************CAN ISR**********************/

现在我的观察是、RX 输入正确运行(RX 开关 case 行中的应用代码被运行、添加了在接收到消息时它将在那里停止的断点)。 但 TX 中断似乎未满足要求。 在 TX Messag 对象中添加断点会在 canaISR 内切换 case 行、但不会被触发。   

因为我已经将 TX 消息对象设置为 CAN_MSG_OBJ_TX_INT_ENABLE、所以我希望 TX 中断正常工作。 RX 消息对象采用类似的设置方式(使用 CAN_MSG_OBJ_RX_INT_ENABLE)、效果很好、因此我不明白为什么 TX 消息对象在这里有问题。

感谢您的回复和建议。

此致、

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

    Wei、  

    首先、我建议您尝试运行"can_ex5_transfer_receive"、它已经过验证、以便测试您的设置。  

    代码看起来没有问题、您是否可以检查 CAN_ERRC 寄存器中传输错误计数器的值来检查传输中是否存在错误。  

    谢谢。

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

    大家好、Sahil:

    感谢您的答复。 实际上、我使用的是  can_ex5_transfer_receive、并获得了我在上面描述的观察结果。

    我将尝试从实验中获取更多详细信息、然后回到此处。  

    BTW、不确定操作是否正确、但我 从 Resource Explorer 中导入了 can_ex5_transmit_receive 示例(离线、我之前已下载 C2000ware)、如下图所示。  

    我从280037文件夹下载了示例代码、但导入的工程似乎具有280039C 的默认目标配置。 我将其更改为280037 (请参阅下面、39C 目标配置附带了导入的项目、我创建了一个名为280037的新配置)、并在280037板上对其进行构建/运行、但不确定是否需要修改其他步骤。  

    此致、

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

    Wei、  

    我建议您在修改用于测试的示例之前、首先尝试从 C2000ware 中立即运行该示例。  

    我从280037文件夹下载了示例代码,但导入的项目似乎具有280039C 的默认目标配置。 我将其更改为280037 (请参阅下面、39C 目标配置附带了导入的项目、我创建了一个名为280037的新配置)、并在280037板上对其进行构建/运行、但不确定是否需要修改其他步骤。  [/报价]

    您无需创建新的目标配置即可运行该示例。 该示例将像现在一样工作。  

    您是否还可以分享您正在使用的设置的详细信息? 具体来说、如果您可以共享一个连接到 CAN 收发器的引脚图、这会有所帮助?

    谢谢。