Hardware manual
RX600 Series CAN Application Programming Interface
R01AN0339EU0203 Rev. 2.03 Page 12 of 29
Mar 23, 2013
R_CAN_TxSet and R_CAN_TxSetXid
Set up a mailbox to transmit
R_CAN_TxSet will write to a mailbox the specified ID, data length and data frame payload, then set the mailbox to
transmit mode and send a frame onto the bus by calling R_CAN_Tx().
R_CAN_TxSetXid does the same, except if this function is used, the ID will be a 29-bit ID.
Format
uint32_t R_CAN_TxSet( const uint32_t ch_nr,
const uint32_t mbox_nr,
const can_frame_t* frame_p,
const uint32_t frame_type );
Arguments
ch_nr 0,1,2,3 Which CAN bus to use. 1-4 channels may be available.
mbox_nr 0-32 Mailbox to use.
frame_p* Pointer to a data frame structure in memory. It is an address to the data
structure containing the ID, DLC and data that constitute the dataframe
the mailbox will transmit.
frame_type DATA_FRAME Send a normal data frame.
REMOTE_FRAME Send a remote data frame request.
Return Values
R_CAN_OK The mailbox was set up for transmission.
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.
Properties
Prototyped in r_can_api.h
Implemented in r_can_api.c
Comments
This function first waits for any previous transmission of the specified mailbox to complete. It then interrupt disables
the mailbox temporarily when setting up the mailbox: Sets the ID value for the mailbox, the Data Length Code
indicated by frame_p, selects dataframe or remote frame request and finally copies the data frame payload bytes (0-7)
into the mailbox. The mailbox is interrupt enabled again unless USE_CAN_POLL was defined. Finally R_CAN_Tx is
called to deliver the message.
Example
#define MY_TX_SLOT 7
can_std_frame_t my_tx_dataframe;
my_tx_dataframe.id = 1;
my_tx_dataframe.dlc = 2;
my_tx_dataframe.data[0] = 0xAA;
my_tx_dataframe.data[1] = 0xBB;
/* Send my frame. */
api_status = R_CAN_TxSet(0, MY_TX_SLOT, &my_tx_dataframe, DATA_FRAME);