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.

Help CAN transmit function selecting the mailbox

Hi All,

I am trying to write some functions to transmit data using the CAN interface in which would be possible to select the mailbox to use in the transmission.

The idea is to pass the Mailbox number as a parameter of the function and then set up the corresponding mailbox inside. I am trying to do it with a switch() and then add a case for each of the 16 mailboxes available for transmission, but the issue is that as I have to set up the ECanaMboxes and ECanaRegs structures for each of them separately,  it results in a HUGE amount of code.

Is there a better way to implement such a feature?

I though of the possibility of using a variable that replace the ECanaMboxes and ECanaRegs field of each mailbox I want to use, so that I use the same code for all of them... for instance:

If I want to use mailbox 10 it would be:

ECanaShadow.CANTRR.all = ECanaRegs.CANTRR.all;

ECanaShadow.CANTRR.bit.B10 = 1;

ECanaRegs.CANTRR.all = ECanaShadow.CANTRR.all;

and it would be great to have a solution like this:

ECanaShadow.CANTRR.all = ECanaRegs.CANTRR.all;

ECanaShadow.CANTRR.bit.mailbox_variable = 1;

ECanaRegs.CANTRR.all = ECanaShadow.CANTRR.all;

I know what I propose is not feasible like this, but I would like to know if using a macro or something like that it is possible to access the registers using a variable

  • Well... I have figured out the way to deal with the Mailboxes data.... Following some of the can examples I created a pointer to the address of the Mailbox 0 and then incrementing this pointer according to the mailbox I want to use...

    volatile struct MBOX *Mailbox  = (void *) 0x6100; 

    if I want to use mailbox 10...

    Mailbox = Mailbox + 10;

    and then 

    Mailbox.MSGID.bit.STDMSGID = Id;

    etc...

    Is there a way to do the same so that I can manipulate the bits in CANME and CANTRS for instance?

    Thank so you much in advance

  • Hi Javier,

    did u get solution to manipulate the bits in CANME, CANMD or CANTRS ???

    if yes then please post solution.

    Thanks