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.

TMS320F28035 issue using the CAN module

Other Parts Discussed in Thread: TMS320F28035

 

I have a TMS320F28035 customer with an issue using the CAN module...

I configured two mailbox to receive different messages. Following is initialization...

EALLOW;  ECanaRegs.CANME.bit.ME0 = 0;  ECanaMboxes.MBOX1.MSGID.bit.AME = 1;   ECanaMboxes.MBOX1.MSGID.all = 0xFFF1FFFF;   ECanaLAMRegs.LAM1.all = 0xFFF0FFFF;   ECanaRegs.CANMD.bit.MD0 = 1;   ECanaRegs.CANME.bit.ME0 = 1;   ECanaRegs.CANME.bit.ME2 = 0;   ECanaMboxes.MBOX2.MSGID.bit.AME = 1;   ECanaMboxes.MBOX2.MSGID.all = 0xFFF2FFFF;   ECanaLAMRegs.LAM2.all = 0xFFF0FFFF;   ECanaRegs.CANMD.bit.MD2 = 1;   ECanaRegs.CANME.bit.ME2 = 1;  

EDIS Mailbox 1 receive CAN message as expected and RMP1 bit set at every CAN message with matching identifier. Mailbox 2 receive only one message after power cycle. Mailbox 2 has valid data (Same as monitored by CAN adapter, spy tool), but RMP2 bit is always 0. I am not using interrupts for CAN. Value of ECanaRegs.CANRMP is zero, which indicates message was not received by other mailbox. Message identifier on CAN bus is 0x10220007, which match mailbox 2.

Following is portion of code which handle mailbox two data...

if(ECanaRegs.CANRMP.bit.RMP2) { ECanaRegs.CANRMP.bit.RMP2 = 0; Read data from mailbox2 }else if(ECanaRegs.CANRML.bit.RML2) { ECanaRegs.CANRMP.bit.RMP2 = 1; }

Can you please suggest possible cause? Does TI have any example code for CAN?

Thanks!

  • Hi Dan,

    I'm checking to see what we have.  Will get back to you shortly.

    Thanks,

    John

  • Your code is a little bit confusing:

    Instruction 2 and 7  disable/enable Malibox0, what has this to do with your question, it is not related to mailbox 1 or 2.

    Instruction 3 and 4 set Mailbox 1 Message ID (which is never enabled), but in wrong order (first bit , then all - instruction 3 is useless).  Same in instructions 9 and 10 for mailbox 2. You did not catch this error because AME is also set to 1 in your 32-bit constant, but it is poor programming technique anyway.

    Mailbox 1 is not  enabled in your code, it will never receive anything

    In the if - statement  you should first read the mailbox and 2nd clear the RMP2 bit.

    The else if - part  you set the RMP - bit if  message 2 has been lost. What is the purpose ot that?  Since the message is lost, it does not make sense to flag a new "receive message pending".

    I would revcommend to start with the CAN examples from contrlolsuite ot to use the University teaching ROM labs for CAN.

     

     

     

     

  • DanR posted question on my behalf. Thank you for quick answer. There was typo during question, but once I change init sequence to following it work.

    /*** Init MailBox 1, Receive Frame 1 ******************/
    ECanaRegs.CANME.bit.ME1 = 0;
    ECanaMboxes.MBOX1.MSGID.all = 0xDFF1FFFF;
    ECanaMboxes.MBOX1.MSGID.bit.AME = 1;
    ECanaLAMRegs.LAM1.all = 0xFFF0FFFF;
    ECanaRegs.CANMD.bit.MD1 = 1;
    ECanaRegs.CANME.bit.ME1 = 1;

    /*** Init MailBox 2, Receive Frame 2******************/
    ECanaRegs.CANME.bit.ME2 = 0;
    ECanaMboxes.MBOX2.MSGID.all = 0xDFF2FFFF;
    ECanaMboxes.MBOX2.MSGID.bit.AME = 1;
    ECanaLAMRegs.LAM2.all = 0xFFF0FFFF;
    ECanaRegs.CANMD.bit.MD2 = 1;
    ECanaRegs.CANME.bit.ME2 = 1;

    I have still one issue. When I am trying to clear RMP1, RMP2 clear automatically. Datasheet suggest to write 1 to clear RMP1. I tried following, but it clear RMP2 regardless.

    ECanaRegs.CANRMP.bit.RMP1 = 1;

    ECanaRegs.CANRMP.bit.RMP1 = 0;

  • Jigar,

    You are NOT writing "just one bit" by using the line "ECanaRegs.CANRMP.bit.RMP1 = 1;", it actually reads the 32 bit CANRMP register, OR with RMP1 bit and writing back to the CANRMP register. If you take a look at the user guide, writing a '1' will clear the corresponding CANRMP bit.

    So if you want to use bit-fields then use a local variable(shadow register), initialize all to 0, set the bits you want to clear to 1 and then write the shadow register to the CAN register to clear.

    Avoid "ECanaRegs.CANRMP.bit.RMP1 = 0;" since it will clear other pending bits, not the bit you intended to clear. Remember writing 0's to this register has no effect.

    Joe