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.

TMS320F2812 Ecan Transmit

Hello

i have an issue with ecan transmitiing: i want to send a message using can and it sends 2 messages:

 

void ConfigMailBox_5_TX(Uint32 PackID)
{
    ECanaRegs.CANTA.bit.TA5 = 1; // clear transmission acknowledge bit

// clear transmission acknowledge bit

    ECanaShadow.CANTA.bit.TA5 = ECanaRegs.CANTA.bit.TA5;
    ECanaShadow.CANTA.bit.TA5 = 1;
    ECanaRegs.CANTA.bit.TA5 = ECanaShadow.CANTA.bit.TA5;   
   
    //ECanaRegs.CANME.bit.ME5 = 0;        // disable mailbox 5   
    // disable mailbox 5
    ECanaShadow.CANME.bit.ME5 = ECanaRegs.CANME.bit.ME5;
    ECanaShadow.CANME.bit.ME5 = 0;
    ECanaRegs.CANME.bit.ME5 = ECanaShadow.CANME.bit.ME5;

    // set standard identifier
    ECanaMboxes.MBOX5.MID.bit.MSGID_H = PackID << 2;
    ECanaMboxes.MBOX5.MID.bit.IDE = 0;    // configure to Standard Identifier   

    //ECanaRegs.CANME.bit.ME5 = 1;        // enable mailbox 5   
    // disable mailbox 5
    ECanaShadow.CANME.bit.ME5 = ECanaRegs.CANME.bit.ME5;
    ECanaShadow.CANME.bit.ME5 = 1;
    ECanaRegs.CANME.bit.ME5 = ECanaShadow.CANME.bit.ME5;   

}

 

void Send()

{

ConfigMailBox_5_TX(Uint32 PackID);

.......some code..........

    // enable transmission of the mailbox 5
    ECanaShadow.CANTRS.bit.TRS5 = ECanaRegs.CANTRS.bit.TRS5;
    ECanaShadow.CANTRS.bit.TRS5 = 1;
    ECanaRegs.CANTRS.bit.TRS5 = ECanaShadow.CANTRS.bit.TRS5;

}

 

if i run this in slow motion using debug, then it sends only one message, the only message i want to send;

else, it puts another message like this: t60103B in front of my message.

 

thanks you

  • Some comments:

    1.) The variable :"ECanaShadow" has been introduced to avoid single bit field accesses to the original 32-bit CAN registers in structure "ECanaRegs".  Your code snippet however writes single bit fields into the original register, which makes the "ECanaShadow" variable useless.

    Try to change your code for all of such lines to:

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

    2.)  your function "ConfigMailBox_5_TX" starts with a clear of bit Transmit acknowledge. This bit is used by the CAN unit to acknowledge a successful transmission. Only after such an acknowledgement your code should clear that bit (by setting it to 1). It does not make sense to set this bit, if there was no previous ack from the CAN unit.

    3.)  your function "Send" sets the transmit request bit (again: use 32-bit access to CANTRS) but then it does not wait until this request has been acknowledged by the CAN - unit. If you run your code in real time, it can happen that you call your function "Send()" a 2nd time, before the 1st transmission has actually been finished.  TO wait for an MBX5 acknowledgement can be done (a) by polling TA5 or (b) by enabling an MBX5 interrupt service.

    I have attached a working example for a CAN transmission, based on polling of TA5. This example is taken from my new C2000 teaching CD-ROM.