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.
16.7.2.4 Receiving a Message
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).
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. 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.
16.7.2.5 Handling of Overload Situations
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 signaling 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 (that is, more than one
message). In this case, all data needed for the message can be collected in the mailboxes and be read at once.
16.7.3 Handling of Remote Frame Mailboxes
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.
16.7.3.1 Requesting Data From Another Node
In this case the mailbox is configured as receive mailbox as mentioned above. To request data from another
node, the CPU needs to do the following:
1. Set the RTR bit in the message control field register (CANMSGCTRL) to 1.
2. Write the correct identifier into the message identifier register (MSGID).
3. Set the CANTRS flag for that mailbox. Since the mailbox is configured as receive, it only sends a remote
request message to the other node.
4. The module stores the answer in that mailbox and sets the RMP bit when it is received. This action can
initiate an interrupt. Also, make sure no other mailbox has the same ID.
5. Read the received message.
Controller Area Network (CAN)
1016
TMS320x2806x Microcontrollers
SPRUH18I – JANUARY 2011 – REVISED JUNE 2022
Copyright © 2022 Texas Instruments Incorporated
Содержание TMS320 2806 Series
Страница 2: ......