3.2.4 Receiving a Message
3.2.5 Handling of Overload Situations
3.3
Handling of Remote Frame Mailboxes
3.3.1 Requesting Data From Another Node
Handling of Remote Frame Mailboxes
www.ti.com
4. Configure the mailbox as a receive mailbox by setting the corresponding flag in the mailbox direction
register (CANMD.3 = 1). Make sure no other bits in this register are affected by this operation.
5. If data in the mailbox is to be protected, the overwrite protection control register (CANOPC) should be
programmed now. This protection is useful if no message must be lost. If OPC is set, the software has
to make sure that an additional mailbox (buffer mailbox) is configured to store ’overflow’ messages.
Otherwise messages can be lost without notification.
Write OPC.3 = 1
6. Enable the mailbox by setting the appropriate flag in the mailbox enable register (CANME). This should
be done by reading CANME, and writing back (CANME |= 0x0008) to make sure no other flag has
changed accidentally.
The object is now configured for the receive mode. Any incoming message for that object is handled
automatically.
This example uses mailbox 3. When a message is received, the corresponding flag in the receive
message pending register (CANRMP) is set to 1 and an interrupt can be initiated. The CPU can then read
the message from the mailbox RAM. Before the CPU reads the message from the mailbox, it should first
clear the RMP bit (RMP.3 = 1). The CPU should also check the receive message lost flag RML.3 = 1.
Depending on the application, the CPU has to decide how to handle this situation.
After reading the data, the CPU needs to check that the RMP bit has not been set again by the module. If
the RMP bit has been set to 1, the data may have been corrupted. The CPU needs to read the data again
because a new message was received while the CPU was reading the old one.
If the CPU is not able to handle important messages fast enough, it may be advisable to configure more
than one mailbox for that identifier. Here is an example where the objects 3, 4, and 5 have the same
identifier and share the same mask. For the SCC, the mask is LAM(3). For the eCAN, each object has its
own LAM: LAM(3), LAM(4), and LAM(5), all of which need to be programmed with the same value.
To make sure that no message is lost, set the OPC flag for objects 4 and 5, which prevents unread
messages from being overwritten. If the CAN module must store a received message, it first checks
mailbox 5. If the mailbox is empty, the message is stored there. If the RMP flag of object 5 is set (mailbox
occupied), the CAN module checks the condition of mailbox 4. If that mailbox is also busy, the module
checks in mailbox 3 and stores the message there since the OPC flag is not set for mailbox 3. If mailbox 3
contents have not been previously read, it sets the RML flag of object 3, which can initiate an interrupt.
It is also advisable to have object 4 generate an interrupt telling the CPU to read mailboxes 4 and 5 at
once. This technique is also useful for messages that require more than 8 bytes of data (i.e., more than
one message). In this case, all data needed for the message can be collected in the mailboxes and be
read at once.
There are two functions for remote frame handling. One is a request by the module for data from another
node, the other is a request by another node for data that the module needs to answer.
In order to request data from another node, the object is configured as receive mailbox. Using object 3 for
this example, the CPU needs to do the following:
1. Set the RTR bit in the message control field register (CANMSGCTRL) to 1.
Write MSGCTRL(3) = 0x12
2. Write the correct identifier into the message identifier register (MSGID).
Write MSGID(3) = 0x4F780000
74
eCAN Configuration
SPRU074F – May 2002 – Revised January 2009