Mikroelektronika MIKROE-350 データシート
CANSPIRead
180
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub function CANSPIRead(dim byref id as longint, dim byref
rd_data
rd_data
as byte[8], dim data_len as byte, dim CAN_RX_MSG_FLAGS as
byte) as byte
Returns
-
0
if nothing is received
-
0xFF
if one of the Receive Buffers is full (message received)
Description
If at least one full Receive Buffer is found, it will be processed in the following way:
- Message ID is retrieved and stored to location provided by the
id
parameter
- Message data is retrieved and stored to a buffer provided by the
rd_data
parameter
- Message length is retrieved and stored to location provided by the
data_len
parameter
- Message flags are retrieved and stored to location provided by the
CAN_RX_MSG_FLAGS
parameter
Parameters:
-
id:
message identifier storage address
-
rd_data:
data buffer (an array of bytes up to 8 bytes in length)
-
data_len:
data length storage address.
-
CAN_RX_MSG_FLAGS:
message flags storage address
Requires
The CANSPI module must be in a mode in which receiving 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
' check the CANSPI module for received messages. If any was
received do something.
dim msg_rcvd, rx_flags, data_len as byte
received do something.
dim msg_rcvd, rx_flags, data_len as byte
rd_data as byte[8]
msg_id
msg_id
as longint
...
CANSPISetOperationMode(CANSPI_MODE_NORMAL,0xFF)
' set NORMAL mode (CANSPI module must be in mode in which
CANSPISetOperationMode(CANSPI_MODE_NORMAL,0xFF)
' set NORMAL mode (CANSPI module must be in mode in which
receive is possible)
...
rx_flags = 0 '
clear message flags
if (msg_rcvd = CANSPIRead(msg_id, rd_data, data_len, rx_flags)
...
rx_flags = 0 '
clear message flags
if (msg_rcvd = CANSPIRead(msg_id, rd_data, data_len, rx_flags)
...
end if