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.

[参考译文] EK-TM4C1294XL:使用 EK-TM4C1294XL 作为主设备并使用 EK-TM4C123GXL 进行 CAN 通信

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1352613/ek-tm4c1294xl-can-communication-using-ek-tm4c1294xl-as-the-master-and-ek-tm4c123gxl

器件型号:EK-TM4C1294XL
主题中讨论的其他器件: EK-TM4C123GXLMSP430FR2353

您好!

我们确认了以 EK-TM4C1294XL 作为主节点并以 EK-TM4C1294XL 作为接收节点的 CAN 通信。 我根据 spna245.pdf 下载了示例代码(spna245.zip)、在接收端执行了[simple_can_tx]和[simple_can_rx]、并确认可以正常执行通信。
https://www.ti.com/lit/an/spna245/spna245.pdf

当使用 EK-TM4C1294XL 作为主设备并将接收端更改为 EK-TM4C123GXL 时、或当与我们自己的产品(MPU:MSP430FR2353/CAN 控制器:MCP2518/CAN 收发器:SN65HVD231DP)连接时、会发生 ACK 错误并且无法执行通信。

BOFF = 0
EWARN = 1
EPASS = 1
RXOK= 0
TXOK= 0
LEC= 0 x 3※ACK 错误

EK-TM4C123GXL 的 CAN 模块是相同的、因此我认为它应该可以正常工作。
"Tempest 和 Firestorm 级器件与 TM4C129x 器件之间的 CAN 模块没有差异。"
https://www.ti.com/lit/an/spma065/spma065.pdf

你能给我一些意见吗?

谢谢。

科诺

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

    尊敬的 Conor:

     您不能在 EK-TM4C123GXL 板上原封不动地运行 simple_can_rx、因为 TM4C129和 TM4C123的系统时钟设置和 CAN 比特率设置不同。  如需了解详情、请参阅 C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\can\simple_rx.c 示例。 如下面突出显示的行所示、其中时钟和比特率设置存在差异。 您必须进行相应更改、以便在 EK-TM4C129GXL 上运行代码。  

    //*****************************************************************************
    //
    // Configure the CAN and enter a loop to receive CAN messages.
    //
    //*****************************************************************************
    int
    main(void)
    {
    #if defined(TARGET_IS_TM4C129_RA0) || \
    defined(TARGET_IS_TM4C129_RA1) || \
    defined(TARGET_IS_TM4C129_RA2)
    uint32_t ui32SysClock;
    #endif

    tCANMsgObject sCANMessage;
    uint8_t pui8MsgData[8];

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal used on your board.
    //
    #if defined(TARGET_IS_TM4C129_RA0) || \
    defined(TARGET_IS_TM4C129_RA1) || \
    defined(TARGET_IS_TM4C129_RA2)
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN |
    SYSCTL_USE_OSC)
    25000000);
    #else
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ);
    #endif

    //
    // Set up the serial console to use for displaying messages. This is
    // just for this example program and is not needed for CAN operation.
    //
    InitConsole();

    //
    // For this example CAN0 is used with RX and TX pins on port B4 and B5.
    // The actual port and pins used may be different on your part, consult
    // the data sheet for more information.
    // GPIO port B needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the GPIO pin muxing to select CAN0 functions for these pins.
    // This step selects which alternate function is available for these pins.
    // This is necessary if your part supports GPIO pin function muxing.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using
    //
    GPIOPinConfigure(GPIO_PB4_CAN0RX);
    GPIOPinConfigure(GPIO_PB5_CAN0TX);

    //
    // Enable the alternate function on the GPIO pins. The above step selects
    // which alternate function is available. This step actually enables the
    // alternate function instead of GPIO for these pins.
    // TODO: change this to match the port/pin you are using
    //
    GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    //
    // The GPIO port and pins have been set up for CAN. The CAN peripheral
    // must be enabled.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);

    //
    // Initialize the CAN controller
    //
    CANInit(CAN0_BASE);

    //
    // Set up the bit rate for the CAN bus. This function sets up the CAN
    // bus timing for a nominal configuration. You can achieve more control
    // over the CAN bus timing by using the function CANBitTimingSet() instead
    // of this one, if needed.
    // In this example, the CAN bus is set to 500 kHz. In the function below,
    // the call to SysCtlClockGet() or ui32SysClock is used to determine the
    // clock rate that is used for clocking the CAN peripheral. This can be
    // replaced with a fixed value if you know the value of the system clock,
    // saving the extra function call. For some parts, the CAN peripheral is
    // clocked by a fixed 8 MHz regardless of the system clock in which case
    // the call to SysCtlClockGet() or ui32SysClock should be replaced with
    // 8000000. Consult the data sheet for more information about CAN
    // peripheral clocking.
    //
    #if defined(TARGET_IS_TM4C129_RA0) || \
    defined(TARGET_IS_TM4C129_RA1) || \
    defined(TARGET_IS_TM4C129_RA2)
    CANBitRateSet(CAN0_BASE, ui32SysClock, 500000);
    #else
    CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
    #endif

    //
    // Enable interrupts on the CAN peripheral. This example uses static
    // allocation of interrupt handlers which means the name of the handler
    // is in the vector table of startup code. If you want to use dynamic
    // allocation of the vector table, then you must also call CANIntRegister()
    // here.
    //
    // CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors
    //
    CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);

    //
    // Enable the CAN interrupt on the processor (NVIC).
    //
    IntEnable(INT_CAN0);

    //
    // Enable the CAN for operation.
    //
    CANEnable(CAN0_BASE);

    //
    // Initialize a message object to be used for receiving CAN messages with
    // any CAN ID. In order to receive any CAN ID, the ID and mask must both
    // be set to 0, and the ID filter enabled.
    //
    sCANMessage.ui32MsgID = 0;
    sCANMessage.ui32MsgIDMask = 0;
    sCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
    sCANMessage.ui32MsgLen = 8;

    //
    // Now load the message object into the CAN peripheral. Once loaded the
    // CAN will receive any message on the bus, and an interrupt will occur.
    // Use message object 1 for receiving messages (this is not the same as
    // the CAN ID which can be any value in this example).
    //
    CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_RX);

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

    尊敬的 Charles:

    好的、我明白。 我想修改示例代码并对其进行测试。

    当使用 EK-TM4C1294XL 作为主器件并将接收端更改为 EK-TM4C123GXL 时、或在连接我们自己的产品(MPU:MSP430FR2353/CAN 控制器:MCP2518/CAN 收发器:SN65HVD231DP)时、出现 ACK 错误并无法执行通信[/报价]。

    请告知在与我们自己的产品通信时、如果有任何需要检查的项目、则会发生 ACK 错误。

    谢谢。

    科诺

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

    尊敬的 Conor:

     我将建议您使用逻辑分析仪、该分析仪可以解读 CAN 数据包、以了解接收节点为何不采用 ACK。 请确保它们在发送节点和接收节点上配置的比特率相同。