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.

eCan transmit problem

Hello.

I am using a TMS320F028016PZA with CCSv3.3. I am trying to implement eCAN, working for the example files (A_to_B_Xmit and back_to_back), but right now I can't transmit any frame.

In order to know where the problem is, I saw the signal TX with an oscilloscope (pin 7), and the level didn't change. But I couldn't believe when I saw the signal had 1V level. I hoped 0V (low level) and 3,3V (high level).

After that, I have checked the voltage in other pins and I get 3,3V as I would have expected. Any idea?

  • Hi Masky,

    Do the examples files work or not?

    Regards,

    Gautam

  • Hi Gautan,

    nop, the programme is always running in the do/while loop, waiting for TA to be set. 

                        ECanaShadow.CANTRS.all = 0;

                        ECanaShadow.CANTRS.bit.TRS25 = 1;     // Set TRS for mailbox under test
                        ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;

                        do
                        {
                              ECanaShadow.CANTA.all = ECanaRegs.CANTA.all;
                        } while(ECanaShadow.CANTA.bit.TA25 == 0 );   // Wait for TA bit to be set..

  • Hi,

    Something seems to be missing here! The example code does work fine... Can you please check with the loopback connections?

    Regards,

    Gautam

  • Hello Gautam,

    I disconnected pin 7 (CANTXA) and CAN transceiver, and I got the signal with the oscilloscope. Now I have 3V, but any frames is sent. So....maybe there is something in the wrong in the initialization? The code is as follow:

    void InitECanaGpio(void)

    {

    GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
    GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // Enable pull-up for GPIO31 (CANTXA)
    GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch qual for GPIO30 (CANRXA)
    GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 for CANTXA operation
    GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Configure GPIO31 for CANRXA operation

    }

    void InitECana(void) // Initialize eCAN-A module
    {
    long i;

    EALLOW; // EALLOW enables access to protected bits

    /* Configure eCAN RX and TX pins for eCAN transmissions using eCAN regs*/

    ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
    ECanaShadow.CANTIOC.bit.TXFUNC = 1;
    ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all;

    ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
    ECanaShadow.CANRIOC.bit.RXFUNC = 1;
    ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;

    /* Configure eCAN for HECC mode - (reqd to access mailboxes 16 thru 31) */
    // HECC mode also enables time-stamping feature

    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.SCB = 1;
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

    /* Initialize all bits of 'Master Control Field' to zero */
    // Some bits of MSGCTRL register come up in an unknown state. For proper operation,
    // all bits (including reserved bits) of MSGCTRL must be initialized to zero

    ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX17.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX18.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX19.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX20.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX21.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX22.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX23.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX24.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX25.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX26.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX27.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX28.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX29.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX30.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX31.MSGCTRL.all = 0x00000000;

    // TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
    // as a matter of precaution.

    ECanaRegs.CANTA.all = 0xFFFFFFFF; /* Clear all TAn bits */

    ECanaRegs.CANRMP.all = 0xFFFFFFFF; /* Clear all RMPn bits */

    ECanaRegs.CANGIF0.all = 0xFFFFFFFF; /* Clear all interrupt flag bits */
    ECanaRegs.CANGIF1.all = 0xFFFFFFFF;


    /* Configure bit timing parameters for eCANA*/
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

    while(ECanaRegs.CANES.bit.CCE != 1 ) {} // Wait for CCE bit to be set..

    ECanaShadow.CANBTC.all = 0;
    // ECanaShadow.CANBTC.bit.BRPREG = 9;
    ECanaShadow.CANBTC.bit.BRPREG = 19; // para SYSCLKOUT = 20 ns => 1/(20 Mhz *5 /2) BRP+1 =20
    ECanaShadow.CANBTC.bit.TSEG2REG = 1;
    ECanaShadow.CANBTC.bit.TSEG1REG = 6;
    ECanaShadow.CANBTC.bit.SAM = 1;
    ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;

    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

    while(ECanaRegs.CANES.bit.CCE == !0 ) {} // Wait for CCE bit to be cleared..

    /* Disable all Mailboxes */
    ECanaRegs.CANME.all = 0; // Required before writing the MSGIDs

    EDIS;

    /* Write to the MSGID field */

    ECanaMboxes.MBOX25.MSGID.all = 0x00000700; // 0x700 <<10

    /* Configure Mailbox 25 as a Transmit mailbox and 20 as a receive*/

    ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
    ECanaShadow.CANMD.bit.MD25 = 0;
    ECanaShadow.CANMD.bit.MD20 = 1;
    ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;

    /* Enable Mailbox under test */

    ECanaShadow.CANME.all = ECanaRegs.CANME.all;
    ECanaShadow.CANME.bit.ME25 = 1;
    ECanaShadow.CANME.bit.ME20 = 1;
    ECanaRegs.CANME.all = ECanaShadow.CANME.all;

    /* Write to DLC field in Master Control reg */

    ECanaMboxes.MBOX25.MSGCTRL.bit.DLC = 8;

    /* Write to the mailbox RAM field */

    ECanaMboxes.MBOX25.MDL.all = 0x55555555;
    ECanaMboxes.MBOX25.MDH.all = 0x55555555;

    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    EALLOW;
    ECanaRegs.CANMIM.all = 0xFFFFFFFF;

    // Configure the eCAN for self test mode
    // Enable the enhanced features of the eCAN.
    EALLOW;
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.STM = 1; // Configure CAN for self-test mode
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;

    /* Begin transmitting */


    for(i=0; i < 3;)
    {
    ECanaShadow.CANTRS.all = 0;
    ECanaShadow.CANTRS.bit.TRS25 = 1; // Set TRS for mailbox under test
    ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;

    while(ECanaRegs.CANTA.bit.TA25 == 0 ) {} // Wait for TA5 bit to be set..

    ECanaShadow.CANTA.all = 0;
    ECanaShadow.CANTA.bit.TA25 = 1; // Clear TA5
    ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;

    // loopcount ++;
    }

    }



    P.D: sorry, but I didn't understand the meaning of loopback (I think in spanish there isn't a translation for this).


    Thank you.



  • Hi,

    Loop back connection means connect CANTXA -> CANRXA; and then checking values of CANRXA whether it matches with the transmitted data or not!

    Regards,

    Gautam

  • Hello Gautam,

    I did this, but I can't receive anything. I always get a stuff bit error, Maybe this depends on how TSEG1 & TSEG2 are configured?

  • Hi Masky,

    But then the sample code is enough for this loopback test, you must not face an issue here. I guess only the documentation would shed some light to your problem.

    Regards,

    Gautam

  • Hi Masky,

    Both MBOX20 and 25 must be configured with the same Message ID. Looks like you have configured only MBOX25 but have forgotten to configure MBOX20with the same message ID.

    ECanaMboxes.MBOX25.MSGID.all = 0x00000700; // 0x700 <<10         // Done

    ECanaMboxes.MBOX20.MSGID.all = 0x00000700; // 0x700 <<10        // Forgotten

    Thanks,

    Vivek