User manual

334
mikoC PRO for dsPIC
MikroElektronika
ECANxWrite
Prototype
unsigned int ECANxWrite(long id, char *Data, unsigned int DataLen, unsigned
int ECAN_TX_MSG_FLAGS);
Description If at least one empty Transmit Buffer is found, the function sends message in the queue for
transmission.
Parameters - id: ECAN message identier. Valid values: all 11 or 29 bit values, depending on message type
(standard or extended)
- Data: data to be sent
- DataLen: data length. Valid values: 0..8
- ECAN_TX_MSG_FLAGS: message ags. Valid values: ECAN_TX_MSG_FLAGS constants. See ECAN_
TX_MSG_FLAGS constants.
Returns - 0 if all Transmit Buffers are busy
- 0xFFFF if at least one Transmit Buffer is empty and available for transmition
Requires The ECAN routines are supported only by MCUs with the ECAN module.
Microcontroller must be connected to ECAN transceiver which is connected to the ECAN bus.
The ECAN module must be in a mode in which transmission is possible. See
ECANxSetOperationMode.
Example
// send message extended ECAN message with appropriate ID and data
unsigned int tx_ags;
char data[8];
unsigned long msg_id;
...
ECAN1SetOperationMode(_ECAN_MODE_NORMAL,0xFF); // set NORMAL mode
(ECAN1 must be in a mode in which transmission is possible)
tx_ags = _ECAN_TX_PRIORITY_0 &
_ECAN_TX_XTD_FRAME &
_ECAN_TX_NO_RTR_FRAME; // set message ags
ECAN1Write(msg_id, data, 1, tx_ags);
Notes - ECAN library routine require you to specify the module you want to use. To select the desired ECAN
module, simply change the letter x in the routine prototype for a number from 1 to 2.
- Number of ECAN modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.