Hardware manual
RX600 Series CAN Application Programming Interface
R01AN0339EU0203 Rev. 2.03 Page 6 of 29
Mar 23, 2013
CAN Bitrate Settings
See API R_CAN_SetBitrate below and the file config_r_can_rapi.h.
8. The CAN API
The API is a set of functions that allow you to use CAN without having to commit attention to all the details of setting
up the CAN peripheral, to be able to easily have your application communicate with other nodes on the network.
Figure 2. The CAN API functions.
Note that the hardware manual is the absolute reference for behavior.
The first group of functions (orange) in Figure 2 is used to initialize the CAN peripheral registers and configure the
MCU’s CAN and transceiver ports. The first function, R_CAN_Create, will by default invoke the rest of the
initialization functions.
The Transmit functions (blue) are used to set up a mailbox to transmit and to check that it actually was sent successfully.
The Receive functions (green) are used to set up a mailbox to receive and to retrieve a message from it.
The Error function (red) checks the CAN bus status of the node.
8.1 API Return Codes
R_CAN_OK Action completed successfully.
R_CAN_NOT_OK Action did not complete successfully.
Usually a more specific return code is used, see below.
R_CAN_SW_BAD_MBX Bad mailbox number.
R_CAN_BAD_CH_NR The channel number does not exist.
R_CAN_BAD_ACTION_TYPE No such action type exists for this function.
R_CAN_MSGLOST Message was overwritten or lost.
R_CAN_NO_SENTDATA No message was sent.
R_CAN_RXPOLL_TMO Polling for received message timed out.
Initialization, Port and Peripheral Control
R_CAN_Create (uint32_t ch_nr);
R_CAN_PortSet (uint32_t ch_nr, uint32_t
action_type
);
[action_type = ENABLE, DISABLE]
R_CAN_Control (uint32_t ch_nr, uint32_t
action_type
);
[action_type = ENTERSLEEP_CANMODE, EXITSLEEP_CANMODE, RESET_CANMODE,
HALT_CANMODE, OPERATE_CANMODE, CANPORT_TEST_LISTEN_ONLY,
CANPORT_TEST_0_EXT_LOOPBACK, CANPORT_TEST_1_INT_LOOPBACK,
CANPORT_RETURN_TO_NORMAL]
R_CAN_SetBitrate (uint32_t ch_nr);
Send
R_CAN_TxSet (uint32_t ch_nr, uint32_t mbox_nr, can_std_frame_t* frame_p, uint32_t frame_type);
R_CAN_TxSetXid (uint32_t ch_nr, uint32_t mbox_nr, can_frame_t* frame_p, uint32_t frame_type);
R_CAN_Tx (uint32_t ch_nr, uint32_t mbox_nr);
R_CAN_TxCheck (uint32_t ch_nr, uint32_t mbox_nr);
R_CAN_TxStopMsg (uint32_t ch_nr, uint32_t mbox_nr);
Receive
R_CAN_RxSet (uint32_t ch_nr, uint32_t mbox_nr, uint32_t stid,
uint
32_t frame_type);
R_CAN_RxSetXid (uint32_t ch_nr, uint32_t mbox_nr, uint32_t xid, uint32_t frame_type);
R_CAN_RxRead (uint32_t ch_nr, uint32_t mbox_nr, can_std_frame_t* frame_p);
R_CAN_RxPoll (uint32_t ch_nr, uint32_t mbox_nr);
R_CAN_RxSetMask (uint32_t ch_nr, uint32_t sid_mask_value, uint32_t mask_reg_nr);
Error Check
R_CAN_CheckErr (uint32_t ch_nr);