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.

CCS/TMS320F28069M: eCAN configuration (can't tx messagebox)

Part Number: TMS320F28069M
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hi all,

I'm working on my first c2000 CAN project.

My CPU is 20MHz xtal clocked with PLL set to 80MHz.

I've some trouble with configuration. My MCU is not able to send MBOX message and loop into TA bit check after TRS setting.

This is my eCANA configuration file:

void
InitECana(void)
{
    //
    // Create a shadow register structure for the CAN control registers.
    // This is needed, since only 32-bit access is allowed to these registers.
    // 16-bit access to these registers could potentially corrupt the register
    // contents or return false data.
    //
    struct ECAN_REGS ECanaShadow;
    
    //
    // Setup variables to initialize mailboxes to zero
    //
    int16 mboxCount;
    volatile struct MBOX *Mailbox = (void *) 0x6100;

    EALLOW;     // EALLOW enables access to protected bits

    //
    // Configure eCAN RX and TX pins for CAN operation 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 registers of the mailboxes 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
    //
    for(mboxCount=0; mboxCount<32; mboxCount++)
    {
        Mailbox->MSGID.all = 0;
        Mailbox->MSGCTRL.all = 0;
        Mailbox->MDH.all = 0;
        Mailbox->MDL.all = 0;
        Mailbox = Mailbox + 1;
    }

    //
    // 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;
    
    //
    // Wait until the CPU has been granted permission to change the
    // configuration registers
    //
    do
    {
        ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 1 );   // Wait for CCE bit to be set

    ECanaShadow.CANBTC.all = 0;
    
    //
    // The following block is for 80 MHz SYSCLKOUT.
    // (40 MHz CAN module clock Bit rate = 250 Kbps)
    // See Note at end of file.
    //
    ECanaShadow.CANBTC.bit.BRPREG = 9;
    ECanaShadow.CANBTC.bit.TSEG2REG = 2;
    ECanaShadow.CANBTC.bit.TSEG1REG = 12;

    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;

    //
    // Wait until the CPU no longer has permission to change the
    // configuration registers
    //
    do
    {
        ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 0 );// Wait for CCE bit to be  cleared

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

    EDIS;
}

...my init code:

void _init_CAN(){
    EALLOW;

/* Write to the MSGID field  */

    ECanaMboxes.MBOX25.MSGID.all = 0x95555555; // Extended Identifier

/* Configure Mailbox under test as a Transmit mailbox */

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

/* Enable Mailbox under test */

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

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

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

/* Write to the mailbox RAM field */

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

    return;
}

...and this is the "sending" function called by timer at regular interval:

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

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

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

    return;
}

The hardware side seem to be correct. I'm using TCAN1042 transceiver and at the other side of the bus is inserted a "Can bus analyzer" terminated on 120Ohm resistor.

Canbus analyzer not indicate bus errors and the voltage levels seems to be correct.

I'm not see nothing into MCU TX CAN pin. I tryed some variations but the problem still remain. The eCAN clock is enabled.
I readed without success "spra876b".

Anyone can help me?