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.

f28035 eCAN: How to reset individual RMP bit?

I am using 5 mail boxes in receive mode with same ID and checking RMP bit to verify whether message is waiting or not for all the 5 mail boxes. My problem is resetting the RMP bit, by writing a 1 to it. I can keep a local copy of RMP.all and clear it with writing all bits. I prefer to clear only the bit which read. How to do that?

I have tried, read RMP.all, ORed with bit (but it is already 1), write back. It resets all the bits corresponds to mailboxes received messages. 

  • Hi, Joy.

    To reset RMP bit you should set only a particular bit of the corresponding mailbox (so called: Write 1-to-Clear). If you read all RMP then write them back, that would lead to reset ALL RMP bits. So, use a shadow register (local copy), set the bit and write it to RMP.all. eCAN has 32bit access (spraa85d.pdf, p. 21-22)

  • Thanks for the reply. I have tried the shadow register method but dint work.

    shadow = ECanaRegs.CANRMP.all; //assume 3 mailboxes received msgs, RMP.all = 7;

    //reading MBOX0

    if (shadow & 1)

    shadow |= 0x1; // but it is already 1, also other 2 bits

     ECanaRegs.CANRMP.all = shadown; // resetting all 3 bits

    ----------------------------

    //next I've tried, just writing 1 bit, all other 0

     ECanaRegs.CANRMP.all = 1;// though not written 1 to BIT1 & BIT2, still all cleared with this write

    Now I am reading, saving the RMPreg, resetting all. OK it works, so for the time being OK.

  • Joy Philipz said:
    shadow = ECanaRegs.CANRMP.all; //assume 3 mailboxes received msgs, RMP.all = 7;

    You shouldn't read RMP register. To reset corresponding bit you should write "1". If you read RMP first than write it back, you would clear all setted bits.

    Joy Philipz said:
    ECanaRegs.CANRMP.all = 1;

    You can't drive that way. This statement is 16bit access while you have to access CANRMP as 32bit wide.

    You may try to force 32bit operation:

    ECanaRegs.CANRMP.all = (Uint32)1;

    Or use shadow register / Uint32 variable for intermediate value.

    PS. Please read PDF that I've referenced before.

  • Joy:

    Assuming you have 3 mailboxes (0,1 and 2), which receive messages. After all 3 mailboxes are full, RMP is 7. To clear RMP of mailbox 0 use:

    ECanaRegs.CANRMP.all = 1;  This instruction will clear bit 0 only and keep bits 1 and 2; RMP = 6.

    The instruction ECanaRegs.CANRMP.bit.RMP0 = 1  will not work, because this will be translated into an assembly OR-Instruction and therefore reset all RMP-bits.

    Anton:

    ECanaRegs.CANRMP.all = 1;  is for sure a 32-bit instruction, because the union member "all" was declared as 32bit. The resulting assembly code is MOVL @0xC,ACC.  No need to force a typecast.