User manual
268
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
CANSPIRead
Prototype
function CANSPIRead(var id : longint; var Data_ : array[8] of byte; var
DataLen: byte; var CAN_RX_MSG_FLAGS : byte) : byte;
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 data parameter
- Message length is retrieved and stored to location provided by the dataLen parameter
- Message ags are retrieved and stored to location provided by the CANSPI_RX_MSG_FLAGS
parameter
Parameters - id: message identier address
- data: an array of bytes up to 8 bytes in length
- dataLen: data length address
- CANSPI_RX_MSG_FLAGS: message ags address. For message receive ags format refer to
CANSPI_RX_MSG_FLAGS constants. See CANSPI_RX_MSG_FLAGS constants.
Returns - 0 if nothing is received
- 0xFFFF if one of the Receive Buffers is full (message received)
Requires The CANSPI module must be in a mode in which receiving 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
// check the CANSPI1 module for received messages. If any was received do
something.
var msg_rcvd, rx_ags, data_len : byte;
data : array[8] of byte;
msg_id : longint;
...
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF); // set NORMAL mode
(CANSPI1 module must be in mode in which receive is possible)
...
rx_ags := 0; // clear message ags
if (msg_rcvd = CANSPIRead(msg_id, data, data_len, rx_ags)) then
begin
...
end;
Notes None.