Mikroelektronika MIKROE-442 데이터 시트
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
271
CANSPIWrite
Prototype
sub function CANSPIWrite(dim id as longint, dim byref Data_ as byte[8], dim
DataLen, CANSPI_TX_MSG_FLAGS as byte) as byte
Description If at least one empty Transmit Buffer is found, the function sends message in the queue for
transmission.
Parameters -
id
: CAN message identifier. Valid values: 11 or 29 bit values, depending on message type (standard
or extended)
-
Data
: data to be sent
-
DataLen
: data length. Valid values: 0..8
-
CANSPI_TX_MSG_FLAGS
: message flags. Valid values:
CANSPI_TX_MSG_FLAGS
constants. See
CANSPI_TX_MSG_FLAGS constants.
Returns
-
0
if all Transmit Buffers are busy
-
0xFFFF
if at least one Transmit Buffer is available
Requires
The CANSPI module must be in mode in which transmission is possible. See
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.
Example
‘ send message extended CAN message with the appropriate ID and data
dim tx_flags as byte
data as byte[8]
msg_id as longint
...
CANSPISetOperationMode(_CAN_MODE_NORMAL,0xFF) ‘ set NORMAL mode (CANSPI1
must be in mode in which transmission is possible)
tx_flags = _CANSPI_TX_PRIORITY_0 and _CANSPI_TX_XTD_FRAME ‘ set message
flags
CANSPIWrite(msg_id, data, 2, tx_flags)
Notes
None.
CANSPI Constants
There is a number of constants predefined in the CANSPI library. You need to be familiar with them in order to be able
to use the library effectively. Check the example at the end of the chapter.
CANSPI_OP_MODE Constants
The
CANSPI_OP_MODE
constants define CANSPI operation mode. Function CANSPISetOperationMode expects one
of these as it’s argument: