Mikroelektronika MIKROE-350 Fiche De Données
CANSPIWrite
181
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub function CANSPIWrite(dim id as longint, dim byref wr_data as
byte[8], dim data_len as byte, dim CAN_TX_MSG_FLAGS as byte) as byte
byte[8], dim data_len as byte, dim CAN_TX_MSG_FLAGS as byte) as byte
Returns
-
0
if all Transmit Buffers are busy
-
0xFF
if at least one Transmit Buffer is available
Description
If at least one empty Transmit Buffer is found, the sub function sends message
in the queue for transmission.
in the queue for transmission.
Parameters:
-
id:
CAN message identifier. Valid values: 11 or 29 bit values, depending on
message type (standard or extended)
-
wr_data:
data to be sent (an array of bytes up to 8 bytes in length)
-
data_len:
data length. Valid values: 1 to 8
-
CAN_RX_MSG_FLAGS:
message flags
Requires
The CANSPI module must be in mode in which transmission is possible. See
CANSPISetOperationMode.
CANSPISetOperationMode.
The CANSPI routines are supported only by MCUs with the SPI module.
MCU has to be properly connected to mikroElektronika's CANSPI Extra Board
or similar hardware. See connection example at the bottom of this page.
or similar hardware. See connection example at the bottom of this page.
Example
' send message extended CAN message with the appropriate ID and
data
dim tx_flags as byte
data
dim tx_flags as byte
rd_data as byte[8]
msg_id as longint
msg_id as longint
...
CANSPISetOperationMode(CAN_MODE_NORMAL, 0xFF) '
set NORMAL mode (CANSPI must be in mode in which transmission is
possible)
set NORMAL mode (CANSPI must be in mode in which transmission is
possible)
tx_flags = CANSPI_TX_PRIORITY_0 ands CANSPI_TX_XTD_FRAME
' set message flags
CANSPIWrite(msg_id, rd_data, 2, tx_flags)
' set message flags
CANSPIWrite(msg_id, rd_data, 2, tx_flags)