
13.2.2 Introducing the function of CAN example code
CAN example code supports the CANopen protocol. It mainly implements three parts of functions: network manage function
(NMT protocol), service data transmission function (SDO protocol), and process data transmission function (PDO protocol). NMT
protocol can manage and monitor slave nodes, include heart beat message. SDO protocol can transmit single or block data. The
PDO protocol can transmit process data that requires real time.
CAN example calls the CANopen interfaces, described in the table below:
Table 45. CAN Net APIs and their description
API name (type)
Description
UNS8 canReceive_driver (CAN_HANDLE fd0, Message * m) Socketcan receive CAN messages
• fd0 – socketcan handle
• m – receive buffer
UNS8 canSend_driver (CAN_HANDLE fd0, Message const *
m)
Socketcan send CAN messages
• fd0 – socketcan handle
• m – CAN message to be sent
void setNodeId(CO_Data* d, UNS8 nodeId)
Set this node id value.
• d – object dictionary
• nodeId – id value (up to 127)
UNS8 setState(CO_Data* d, e_nodeState newState)
Set node state
• d – object dictionary
• newState – The state that needs to be set
Returns 0 if ok, > 0 on error
void canDispatch(CO_Data* d, Message *m)
CANopen handles data frames that CAN receive.
• d – object dictionary
• m – Received CAN message
void timerForCan(void)
CANopen virtual clock counter.
UNS8 sendPDOrequest (CO_Data * d, UNS16 RPDOIndex)
Master node requests slave node to feedback specified data.
• d – object dictionary
• RPDOIndex – index value of specified data
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId,
UNS16 index, UNS8 subIndex, UNS8 dataType,
SDOCallback_t Callback, UNS8 useBlockMode)
The master node gets the specified data from the slave node.
• d – object dictionary
• nodeId – the id value of slave node
• index – the index value of the specified data
• subIndex – the subindex value of the specified data
Table continues on the next page...
NXP Semiconductors
FlexCAN
Open Industrial User Guide, Rev. 1.8, 05/2020
User's Guide
169 / 199