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.

[参考译文] F28M35H52C:M3内核上的 CAN1不工作

Guru**** 2538950 points
Other Parts Discussed in Thread: CONTROLSUITE

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1011025/f28m35h52c-can1-on-the-m3-core-not-working

器件型号:F28M35H52C
Thread 中讨论的其他器件:controlSUITE

您好!  

我正在使用 M3内核并使用 GPIO_PB4 (CAN0RX)和5 (CAN0TX)上的 CAN0接口。 到目前为止、这种方法效果非常好。
现在、我需要第二个 CAN 接口、只需在现有的 CAN0基础上使用 GPIO_PB0 (CAN1TX)上的 CAN1和2 (CAN1RX)上的 CAN1。

我的初始化过程基本上是从已经在工作的 CAN0复制粘贴、我认为这是从 CAN_loopback 示例中获取的。

void
can_init(void)
{
#if (CAN0_ACTIVE==1)
    // 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.
	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.
	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);
    // Setup CAN to be clocked off the M3/Master subsystem clock
    CANClkSourceSelect(CAN0_BASE, CAN_CLK_M3);
    // 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() 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() should be replaced with 8000000.  Consult the data
    // sheet for more information about CAN peripheral clocking.
    CANBitRateSet(CAN0_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED), 500000);
    // Enable the CAN for operation.
    CANEnable(CAN0_BASE);
#endif
#if (CAN1_ACTIVE==1)
    // 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.
    GPIOPinConfigure(GPIO_PB2_CAN1RX);
    GPIOPinConfigure(GPIO_PB0_CAN1TX);
    // 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.
    GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_0);
	// The GPIO port and pins have been set up for CAN.  The CAN peripheral
	// must be enabled.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1);
	// Initialize the CAN controller
    CANInit(CAN1_BASE);
    // Setup CAN to be clocked off the M3/Master subsystem clock
    CANClkSourceSelect(CAN1_BASE, CAN_CLK_M3);
    // 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() 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() should be replaced with 8000000.  Consult the data
    // sheet for more information about CAN peripheral clocking.
    CANBitRateSet(CAN1_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED), 500000);
    // Enable the CAN for operation.
    CANEnable(CAN1_BASE);
#endif

处理消息的循环部分正在任务中运行、而不使用 CAN 的任何中断、并且已经与 CAN0配合使用。

void canTask(void)
{
    //Tx Messages (We send to external CAN device)
    sTXCAN_1.ulMsgID = 0x1;                    											// CAN message ID
    sTXCAN_1.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_1.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_1.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_1);   				// size of message in byte
    sTXCAN_1.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_1;  	// ptr to message content

    sTXCAN_2.ulMsgID = 0x2;                    											// CAN message ID
    sTXCAN_2.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_2.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_2.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_2);   				// size of message in byte
    sTXCAN_2.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_2;  	// ptr to message content

    sTXCAN_3.ulMsgID = 0xAF;                    										// CAN message ID
    sTXCAN_3.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_3.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_3.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_3);   				// size of message in byte
    sTXCAN_3.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_3;  	// ptr to message content

    sTXCAN_4.ulMsgID = 0xC2;                    										// CAN message ID
    sTXCAN_4.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_4.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_4.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_4);   				// size of message in byte
    sTXCAN_4.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_4;  	// ptr to message content

    sTXCAN_5.ulMsgID = 0xB0;                    										// CAN message ID
    sTXCAN_5.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_5.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_5.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_5);   				// size of message in byte
    sTXCAN_5.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_5;  	// ptr to message content

    sTXCAN_6.ulMsgID = 0xA1;                    										// CAN message ID
    sTXCAN_6.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_6.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_6.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_6);   				// size of message in byte
    sTXCAN_6.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_6;  	// ptr to message content

    sTXCAN_7.ulMsgID = 0xA2;                    										// CAN message ID
    sTXCAN_7.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_7.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_7.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_7);   				// size of message in byte
    sTXCAN_7.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_7;  	// ptr to message content

    sTXCAN_8.ulMsgID = 0xA3;                    										// CAN message ID
    sTXCAN_8.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_8.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_8.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_8);   				// size of message in byte
    sTXCAN_8.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_8;  	// ptr to message content

    sTXCAN_9.ulMsgID = 0xA4;                    										// CAN message ID
    sTXCAN_9.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_9.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_9.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_9);   				// size of message in byte
    sTXCAN_9.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_9;  	// ptr to message content

    sTXCAN_10.ulMsgID = 0xA5;                    										// CAN message ID
    sTXCAN_10.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_10.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_10.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_10);   				// size of message in byte
    sTXCAN_10.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_10;  	// ptr to message content

    sTXCAN_11.ulMsgID = 0xA7;                    										// CAN message ID
    sTXCAN_11.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_11.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_11.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_11);   				// size of message in byte
    sTXCAN_11.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_11;  	// ptr to message content

    sTXCAN_12.ulMsgID = 0xB1;                    										// CAN message ID
    sTXCAN_12.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_12.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_12.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_12);   				// size of message in byte
    sTXCAN_12.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_12;  	// ptr to message content

    sTXCAN_13.ulMsgID = 0xB2;                    										// CAN message ID
    sTXCAN_13.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_13.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_13.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_13);   				// size of message in byte
    sTXCAN_13.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_13;  	// ptr to message content

    sTXCAN_14.ulMsgID = 0xB3;                    										// CAN message ID
    sTXCAN_14.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_14.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_14.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_14);   				// size of message in byte
    sTXCAN_14.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_14;  	// ptr to message content

    sTXCAN_15.ulMsgID = 0xD7;                    										// CAN message ID
    sTXCAN_15.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_15.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_15.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_15);   				// size of message in byte
    sTXCAN_15.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_15;  	// ptr to message content

    sTXCAN_16.ulMsgID = 0xFA;                    										// CAN message ID
    sTXCAN_16.ulMsgIDMask = 0;                    										// no mask needed for TX
    sTXCAN_16.ulFlags = MSG_OBJ_TX_INT_ENABLE;    										// enable interrupt on TX
    sTXCAN_16.ulMsgLen = sizeof(c28_to_m3_shadow.CAN_C28_to_M3.send_16);   				// size of message in byte
    sTXCAN_16.pucMsgData = (unsigned char*) &c28_to_m3_shadow.CAN_C28_to_M3.send_16;  	// ptr to message content

    //Rx Messages (We get from external CAN device)
    sRXCAN_1.ulMsgID = 0x3;                      										// CAN message ID
    sRXCAN_1.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_1.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_1.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_1.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_1;	  		// ptr to message content

    sRXCAN_2.ulMsgID = 0x4;                      										// CAN message ID
    sRXCAN_2.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_2.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_2.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_2.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_2;			// ptr to message content

    sRXCAN_3.ulMsgID = 0x5;                      										// CAN message ID
    sRXCAN_3.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_3.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_3.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_3.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_3;			// ptr to message content

    sRXCAN_4.ulMsgID = 0x6;                      										// CAN message ID
    sRXCAN_4.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_4.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_4.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_4.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_4;			// ptr to message content

    sRXCAN_5.ulMsgID = 0x7;                      										// CAN message ID
    sRXCAN_5.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_5.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_5.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_5.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_5;			// ptr to message content

    sRXCAN_6.ulMsgID = 0x9;                      										// CAN message ID
    sRXCAN_6.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_6.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_6.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_6.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_6;			// ptr to message content

    sRXCAN_7.ulMsgID = 0x10;                      										// CAN message ID
    sRXCAN_7.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_7.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_7.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_7.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_7;			// ptr to message content

    sRXCAN_8.ulMsgID = 0x11;                      										// CAN message ID
    sRXCAN_8.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_8.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_8.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_8.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_8;			// ptr to message content

    sRXCAN_9.ulMsgID = 0x12;                      										// CAN message ID
    sRXCAN_9.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_9.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_9.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_9.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_9;			// ptr to message content

    sRXCAN_10.ulMsgID = 0x13;                      										// CAN message ID
    sRXCAN_10.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_10.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_10.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_10.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_10;		// ptr to message content

    sRXCAN_11.ulMsgID = 0x14;                      										// CAN message ID
    sRXCAN_11.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_11.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_11.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_11.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_11;		// ptr to message content

    sRXCAN_12.ulMsgID = 0x15;                      										// CAN message ID
    sRXCAN_12.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_12.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_12.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_12.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_12;		// ptr to message content

    sRXCAN_13.ulMsgID = 0x16;                      										// CAN message ID
    sRXCAN_13.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_13.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_13.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_13.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_13;		// ptr to message content

    sRXCAN_14.ulMsgID = 0x17;                      										// CAN message ID
    sRXCAN_14.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_14.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_14.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_14.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_14;		// ptr to message content

    sRXCAN_15.ulMsgID = 0x18;                      										// CAN message ID
    sRXCAN_15.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_15.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_15.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_15.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_15;		// ptr to message content

    sRXCAN_16.ulMsgID = 0x19;                      										// CAN message ID
    sRXCAN_16.ulMsgIDMask = 0;                    										// no mask needed for TX
    sRXCAN_16.ulFlags = MSG_OBJ_NO_FLAGS;         										//
    sRXCAN_16.ulMsgLen = 8;                       										// size of message in byte
    sRXCAN_16.pucMsgData = (unsigned char*) &m3_to_c28.CAN_M3_to_C28.receive_16;		// ptr to message content
	while(1)
	{
		gCANSendCnt1++;
		gCANSendCnt2++;

        // Setup the message object being used to receive messages
		CANMessageSet(CAN1_BASE, 1, &sRXCAN_1, MSG_OBJ_TYPE_RX);
		CANMessageSet(CAN1_BASE, 2, &sRXCAN_2, MSG_OBJ_TYPE_RX);
		CANMessageSet(CAN1_BASE, 3, &sRXCAN_3, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 4, &sRXCAN_4, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 5, &sRXCAN_5, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 6, &sRXCAN_6, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 7, &sRXCAN_7, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 8, &sRXCAN_8, MSG_OBJ_TYPE_RX);

        CANMessageSet(CAN1_BASE, 9, &sRXCAN_9, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 10, &sRXCAN_10, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 11, &sRXCAN_11, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 12, &sRXCAN_12, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 13, &sRXCAN_13, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 14, &sRXCAN_14, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 15, &sRXCAN_15, MSG_OBJ_TYPE_RX);
        CANMessageSet(CAN1_BASE, 16, &sRXCAN_16, MSG_OBJ_TYPE_RX);


        // wait until the next message cycle is triggered by c28
        Semaphore_pend(semaphore_CAN, BIOS_WAIT_FOREVER);


        /* CAN SEND MSG WITH CAN_SEND1_INTERVAL */
        	// Update TX Messages 1 every x ms
			if (gCANSendCnt1 % CAN_SEND_INTERVAL_1 == 0) {
				gCANSendCnt1 = 0;

				static Uint64 CAN_Send1_alive_cnt = 0;

				CAN_Send1_alive_cnt++;
				c28_to_m3_shadow.CAN_C28_to_M3.send_16 = CAN_Send1_alive_cnt;

			// Send the CAN message using object number 1 (not the same thing as
			// CAN ID). There are 32 objects (1-32) available. This function will cause
			// the message to be transmitted right away.
			CANMessageSet(CAN1_BASE, 17, &sTXCAN_1, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 18, &sTXCAN_2, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 19, &sTXCAN_3, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 20, &sTXCAN_4, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 21, &sTXCAN_5, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 22, &sTXCAN_6, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 23, &sTXCAN_7, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 24, &sTXCAN_8, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 25, &sTXCAN_9, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 26, &sTXCAN_10, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 27, &sTXCAN_11, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 28, &sTXCAN_12, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 29, &sTXCAN_13, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 30, &sTXCAN_14, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 31, &sTXCAN_15, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 32, &sTXCAN_16, MSG_OBJ_TYPE_TX);
        }


		/* CAN SEND MSG WITH CAN_SEND2_INTERVAL */

			// Update TX Messages 2 every x ms
			if (gCANSendCnt2 % CAN_SEND_INTERVAL_2 == 0) {
				gCANSendCnt2 = 0;

				static Uint64 CAN_Send2_alive_cnt = 0;

				CAN_Send2_alive_cnt++;
				c28_to_m3_shadow.CAN_C28_to_M3.send_15 = CAN_Send2_alive_cnt;

			// Send the CAN message using object number 1 (not the same thing as
			// CAN ID). There are 32 objects (1-32) available. This function will cause
			// the message to be transmitted right away.
//			CANMessageSet(CAN1_BASE, 17, &sTXCAN_1, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 18, &sTXCAN_2, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 19, &sTXCAN_3, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 20, &sTXCAN_4, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 21, &sTXCAN_5, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 22, &sTXCAN_6, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 23, &sTXCAN_7, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 24, &sTXCAN_8, MSG_OBJ_TYPE_TX);

//			CANMessageSet(CAN1_BASE, 25, &sTXCAN_9, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 26, &sTXCAN_10, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 27, &sTXCAN_11, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 28, &sTXCAN_12, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 29, &sTXCAN_13, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 30, &sTXCAN_14, MSG_OBJ_TYPE_TX);
			CANMessageSet(CAN1_BASE, 31, &sTXCAN_15, MSG_OBJ_TYPE_TX);
//			CANMessageSet(CAN1_BASE, 32, &sTXCAN_16, MSG_OBJ_TYPE_TX);
        }

        //alive counter
		alive_ctr = alive_ctr + 1;
		if(alive_ctr >= 100)
			alive_ctr = 1;

		CANMessageGet(CAN1_BASE, 1, &sRXCAN_1, true);
		CANMessageGet(CAN1_BASE, 2, &sRXCAN_2, true);
		CANMessageGet(CAN1_BASE, 3, &sRXCAN_3, true);
		CANMessageGet(CAN1_BASE, 4, &sRXCAN_4, true);
		CANMessageGet(CAN1_BASE, 5, &sRXCAN_5, true);
		CANMessageGet(CAN1_BASE, 6, &sRXCAN_6, true);
		CANMessageGet(CAN1_BASE, 7, &sRXCAN_7, true);
		CANMessageGet(CAN1_BASE, 8, &sRXCAN_8, true);
		CANMessageGet(CAN1_BASE, 9, &sRXCAN_9, true);
		CANMessageGet(CAN1_BASE, 10, &sRXCAN_10, true);
		CANMessageGet(CAN1_BASE, 11, &sRXCAN_11, true);
		CANMessageGet(CAN1_BASE, 12, &sRXCAN_12, true);
		CANMessageGet(CAN1_BASE, 13, &sRXCAN_13, true);
		CANMessageGet(CAN1_BASE, 14, &sRXCAN_14, true);
		CANMessageGet(CAN1_BASE, 15, &sRXCAN_15, true);
		CANMessageGet(CAN1_BASE, 16, &sRXCAN_16, true);

		IPCMtoCFlagSet(IPC_FLAG6);	// benachrichtige c28 -> neue Daten
	}

}

现在、我只是尝试发送和接收所有通过 CAN0处理的消息、现在使用 CAN1、正如上面的代码所示、但 CAN1TX 引脚上的信号对我来说似乎非常奇怪。

首先是 CAN0TX 线路的图片、当所有这些消息都通过 CAN0 (蓝色信号)发送时:

然后、当我通过 CAN1发送所有这些消息时、我假设该信号看起来与之前通过 CAN0发送的信号相同、但它看起来是这样的(红色信号、示波器上的偏移负5V):

在我看来、这看起来不像 CAN 消息、更像是完美的16kHz PWM 信号。  

有人能解释一下这个巴维霍尔吗? 初始化过程是否有问题?

我已经检查了 CAN1管脚是否由 M3内核控制、而不是由 C28控制。

我还检查了 PB0和 PB2引脚是否在代码中的其他位置被初始化、没有发现任何内容。

我清理了项目并重建了它。

我真的不知道如何继续。 有人提出了好的建议吗?

这是非常多的

Michael

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

    Michael、

                 示波器图像不够清晰、无法读取时间标度。 我的第一印象是低脉冲可能有点类似。 但在仔细检查脉冲宽度后,它看起来并不像一个东西。 我同意您的观点,它看起来根本不像有效的 CAN 帧。 假设 CAN1具有正常工作的收发器电路、如 CAN0。 即两个 CAN 都具有正常工作的收发器。  

    您可以在 C:\ti\controlSUITE\device_support\f28m35x\v220\F28M35x_examples_Master\CAN_loopback\m3中尝试 CAN_loopback。 这是一个非常直接的示例。 请勿激活任何其他外设或运行任何其他代码。 使器件运行此示例、而不执行任何其他操作。

    请下载我的应用报告 http://www.ti.com/lit/sprace5。 它有许多经过测试的示例。 我请求您查看提供的调试提示。 大多数 CAN 问题都可以通过查看此检查清单来解决。

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

    您好、Haresh、

    感谢您的回复。

    首先、是的、两个 CAN 都有一个相似且正确的外部电路。

    我按照提示只尝试 CAN_loopback 示例、而在 μ µC 上没有其他尝试。 该示例同时适用于 CAN0和 CAN1。 我能够测量两个通道上的 CAN 帧。 我尝试找出回送示例和代码之间的区别、但没有发现任何问题。 但我注意到示例中的测试模式寄存器、并在代码中尝试了 CAN1的测试模式。 在测试模式下、我能够在  适当的引脚上测量 CAN1处的帧。

    我不能完全理解为什么我的代码中的 CAN0和 CAN1的运行方式与回送示例的代码不同。 因此、实际上、我刚刚对测量的信号感到不安。 如果我已经将 CAN1 H/L 连接到另一个器件、我相信它从一开始就能正常工作。 现在、我能够通过 CAN 高电平和低电平从外部连接 CAN0和 CAN1、并在它们之间发送消息。

    尽管如此、您的提示帮助我解决了问题、同时也感谢应用报告的链接。 可能对未来有所帮助。

    此致  

    Michael