CANSPI Library

The SPI module is available with a number of the ARM MCUs. The mikroPascal PRO for ARM provides a library (driver) for working with mikroElektronika's CANSPI Add-on boards (with MCP2515 or MCP2510) via SPI interface.

The CAN is a very robust protocol that has error detection and signalization, self–checking and fault confinement. Faulty CAN data and remote frames are re-transmitted automatically, similar to the Ethernet.

Data transfer rates depend on distance. For example, 1 Mbit/s can be achieved at network lengths below 40m while 250 Kbit/s can be achieved at network lengths below 250m. The greater distance the lower maximum bitrate that can be achieved. The lowest bitrate defined by the standard is 200Kbit/s. Cables used are shielded twisted pairs.

CAN supports two message formats:

  Important :

Library Dependency Tree

CANSPI Library Dependency Tree

External dependencies of CANSPI Library

Stellaris

The following variables must be defined in all projects using CANSPI Library: Description : Example :
var CanSpi_CS : sbit; sfr; external; Chip Select line. var CanSpi_CS : sbit at GPIO_PORTA_DATA0_bit;
var CanSpi_Rst : sbit; sfr; external; Reset line. var CanSpi_Rst : sbit at GPIO_PORTA_DATA3_bit;
var CanSpi_CS_Direction : sbit; sfr; external; Direction of the Chip Select pin. var CanSpi_CS_Direction : sbit at GPIO_PORTA_DIR0_bit;
var CanSpi_Rst_Direction : sbit; sfr; external; Direction of the Reset pin. var CanSpi_Rst_Direction : sbit at GPIO_PORTA_DIR3_bit;

MSP432

The following variables must be defined in all projects using CANSPI Library: Description : Example :
var CanSpi_CS : sbit; sfr; external; Chip Select line. var CanSpi_CS : sbit at DIO_P5OUT.B2;
var CanSpi_Rst : sbit; sfr; external; Reset line. var CanSpi_Rst : sbit at DIO_P5OUT.B3;
var CanSpi_CS_Direction : sbit; sfr; external; Direction of the Chip Select pin. var CanSpi_CS_Direction : sbit at DIO_P5DIR.B2;
var CanSpi_Rst_Direction : sbit; sfr; external; Direction of the Reset pin. var CanSpi_Rst_Direction : sbit at DIO_P5DIR.B3;

STM32

The following variables must be defined in all projects using CANSPI Library: Description : Example :
var CanSpi_CS : sbit; sfr; external; Chip Select line. var CanSpi_CS : sbit at GPIOB_ODR.B0;
var CanSpi_Rst : sbit; sfr; external; Reset line. var CanSpi_Rst : sbit at GPIOB_ODR.B2;

CEC1x02

The following variables must be defined in all projects using CANSPI Library: Description : Example :
var CanSpi_CS : sbit; sfr; external; Chip Select line. var CanSpi_CS : sbit at GPIO_OUTPUT_PIN_146_bit;
var CanSpi_Rst : sbit; sfr; external; Reset line. var CanSpi_Rst : sbit at GPIO_OUTPUT_PIN_027_bit;

Library Routines

CANSPISetOperationMode

Prototype

procedure CANSPISetOperationMode(mode : byte; WAIT: byte);

Description

Sets the CANSPI module to requested mode.

Parameters
  • mode: CANSPI module operation mode. Valid values: CANSPI_OP_MODE constants. See CANSPI_OP_MODE constants.
  • WAIT: CANSPI mode switching verification request. If WAIT == 0, the call is non-blocking. The function does not verify if the CANSPI module is switched to requested mode or not. Caller must use CANSPIGetOperationMode to verify correct operation mode before performing mode specific operation. If WAIT != 0, the call is blocking – the function won’t “return” until the requested mode is set.
Returns

Nothing.

Requires

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.

Example
// set the CANSPI module into configuration mode (wait inside CANSPISetOperationMode until this mode is set)
CANSPISetOperationMode(_CANSPI_MODE_CONFIG, 0xFF);
Notes

None.

CANSPIGetOperationMode

Prototype

function CANSPIGetOperationMode() : byte;

Description

The function returns current operation mode of the CANSPI module. Check CANSPI_OP_MODE constants or device datasheet for operation mode codes.

Parameters

None.

Returns

Current operation mode.

Requires

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.

Example
// check whether the CANSPI module is in Normal mode and if it is do something.
if (CANSPIGetOperationMode() = _CANSPI_MODE_NORMAL) then
begin
  ...
end;
Notes

None.

CANSPIInitialize

Prototype

procedure CANSPIInitialize(SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CANSPI_CONFIG_FLAGS : char);

Description

Initializes the CANSPI module.

Stand-Alone CAN controller in the CANSPI module is set to:

  • Disable CAN capture
  • Continue CAN operation in Idle mode
  • Do not abort pending transmissions
  • Fcan clock : 4*Tcy (Fosc)
  • Baud rate is set according to given parameters
  • CAN mode : Normal
  • Filter and mask registers IDs are set to zero
  • Filter and mask message frame type is set according to CANSPI_CONFIG_FLAGS value

SAM, SEG2PHTS, WAKFIL and DBEN bits are set according to CANSPI_CONFIG_FLAGS value.

Parameters
  • SJW as defined in MCU's datasheet (CAN Module)
  • BRP as defined in MCU's datasheet (CAN Module)
  • PHSEG1 as defined in MCU's datasheet (CAN Module)
  • PHSEG2 as defined in MCU's datasheet (CAN Module)
  • PROPSEG as defined in MCU's datasheet (CAN Module)
  • CANSPI_CONFIG_FLAGS is formed from predefined constants. See CANSPI_CONFIG_FLAGS constants.
Returns

Nothing.

Requires

External dependencies of the library from the top of the page must be defined before using this function.

The CANSPI routines are supported only by MCUs with the SPI module.

The SPI module needs to be initialized. See the SPIx_Init and SPIx_Init_Advanced routines.

MCU has to be properly connected to mikroElektronika's CANSPI Extra Board or similar hardware.

Example

Stellaris

// CANSPI module connections
var CanSpi_CS            : sbit at GPIO_PORTA_DATA0_bit;
    CanSpi_Rst           : sbit at GPIO_PORTA_DATA3_bit;
    CanSpi_CS_Direction  : sbit at GPIO_PORTA_DIR0_bit;
    CanSpi_Rst_Direction : sbit at GPIO_PORTA_DIR3_bit;
// End CANSPI module connections

var CANSPI_Init_Flags: word;
...  
CANSPI_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and
                   _CANSPI_CONFIG_PHSEG2_PRG_ON  and
                   _CANSPI_CONFIG_STD_MSG        and
                   _CANSPI_CONFIG_DBL_BUFFER_ON  and
                   _CANSPI_CONFIG_VALID_XTD_MSG  and
                   _CANSPI_CONFIG_LINE_FILTER_OFF;
...
SPI1_Init();                                                   // initialize SPI1 module
CANSPIInitialize(1,3,3,3,1,CANSPI_Init_Flags);   // initialize CANSPI

Stellaris

// CANSPI module connections
var CanSpi_CS            : sbit at DIO_P5OUT.B2;
    CanSpi_Rst           : sbit at DIO_P5OUT.B3;
    CanSpi_CS_Direction  : sbit at DIO_P5DIR.B2;
    CanSpi_Rst_Direction : sbit at DIO_P5DIR.B3;
// End CANSPI module connections

var CANSPI_Init_Flags: word;
...  
CANSPI_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and
                   _CANSPI_CONFIG_PHSEG2_PRG_ON  and
                   _CANSPI_CONFIG_STD_MSG        and
                   _CANSPI_CONFIG_DBL_BUFFER_ON  and
                   _CANSPI_CONFIG_VALID_XTD_MSG  and
                   _CANSPI_CONFIG_LINE_FILTER_OFF;
...
SPI1_Init();                                                   // initialize SPI1 module
CANSPIInitialize(1,3,3,3,1,CANSPI_Init_Flags);   // initialize CANSPI

STM32

// CANSPI module connections
var CanSpi_CS            : sbit at GPIOB_ODR.B0;
    CanSpi_Rst           : sbit at GPIOB_ODR.B2;
// End CANSPI module connections

var CANSPI_Init_Flags: word;
...  
Can_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and    // form value to be used
                  _CANSPI_CONFIG_PHSEG2_PRG_ON and    // with CANSPIInit
                  _CANSPI_CONFIG_XTD_MSG and
                  _CANSPI_CONFIG_DBL_BUFFER_ON and
                  _CANSPI_CONFIG_VALID_XTD_MSG;
...
// Initialize SPI module
SPI1_Init_Advanced(_SPI_FPCLK_DIV4, _SPI_MASTER  or _SPI_8_BIT or
                   _SPI_CLK_IDLE_LOW or _SPI_FIRST_CLK_EDGE_TRANSITION or
                   _SPI_MSB_FIRST or _SPI_SS_DISABLE or _SPI_SSM_ENABLE or _SPI_SSI_1,
                   @_GPIO_MODULE_SPI1_PB345);

CANSPIInitialize(1,3,3,3,1,CANSPI_Init_Flags);   // initialize CANSPI

CEC1x02

// CANSPI module connections
var CanSpi_CS            : sbit at GPIO_OUTPUT_PIN_146_bit;
    CanSpi_Rst           : sbit at GPIO_OUTPUT_PIN_027_bit;
// End CANSPI module connections

var CANSPI_Init_Flags: word;
...  

GPIO_Digital_Output(@GPIO_PORT_020_027, _GPIO_PINMASK_7);
GPIO_Digital_Output(@GPIO_PORT_140_147, _GPIO_PINMASK_6);

Can_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and    // form value to be used
                  _CANSPI_CONFIG_PHSEG2_PRG_ON and    // with CANSPIInit
                  _CANSPI_CONFIG_XTD_MSG and
                  _CANSPI_CONFIG_DBL_BUFFER_ON and
                  _CANSPI_CONFIG_VALID_XTD_MSG;
...


// Initialize SPI1 module
SPI0_Init_Advanced(1000000,0x00,0x00);

CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);
Notes
  • CANSPI mode NORMAL will be set on exit.

CANSPISetBaudRate

Prototype

procedure CANSPISetBaudRate(SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CANSPI_CONFIG_FLAGS : byte);

Returns

Nothing.

Description

Sets the CANSPI module baud rate. Due to complexity of the CAN protocol, you can not simply force a bps value. Instead, use this function when the CANSPI module is in Config mode.

SAM, SEG2PHTS and WAKFIL bits are set according to CANSPI_CONFIG_FLAGS value. Refer to datasheet for details.

Parameters
  • SJW as defined in MCU's datasheet (CAN Module)
  • BRP as defined in MCU's datasheet (CAN Module)
  • PHSEG1 as defined in MCU's datasheet (CAN Module)
  • PHSEG2 as defined in MCU's datasheet (CAN Module)
  • PROPSEG as defined in MCU's datasheet (CAN Module)
  • CANSPI_CONFIG_FLAGS is formed from predefined constants. See CANSPI_CONFIG_FLAGS constants.
Returns

Nothing.

Requires

The CANSPI module must be in Config mode, otherwise the function will be ignored. 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
// set required baud rate and sampling rules
var CANSPI_CONFIG_FLAGS : byte;
...  
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);           // set CONFIGURATION mode (CANSPI module must be in config mode for baud rate settings)
CANSPI_CONFIG_FLAGS := _CANSPI_CONFIG_SAMPLE_THRICE and
                   _CANSPI_CONFIG_PHSEG2_PRG_ON  and
                   _CANSPI_CONFIG_STD_MSG        and
                   _CANSPI_CONFIG_DBL_BUFFER_ON  and
                   _CANSPI_CONFIG_VALID_XTD_MSG  and
                   _CANSPI_CONFIG_LINE_FILTER_OFF;
CANSPISetBaudRate(1, 1, 3, 3, 1, CANSPI_CONFIG_FLAGS);
Notes

None.

CANSPISetMask

Prototype

procedure CANSPISetMask(CANSPI_MASK : byte; val : longint; CANSPI_CONFIG_FLAGS : byte);

Description

Configures mask for advanced filtering of messages. The parameter value is bit-adjusted to the appropriate mask registers.

Parameters
  • CANSPI_MASK: CAN module mask number. Valid values: CANSPI_MASK constants. See CANSPI_MASK constants.
  • val: mask register value. This value is bit-adjusted to appropriate buffer mask registers
  • CANSPI_CONFIG_FLAGS: selects type of message to filter. Valid values:
    • _CANSPI_CONFIG_ALL_VALID_MSG,
    • _CANSPI_CONFIG_MATCH_MSG_TYPE & _CANSPI_CONFIG_STD_MSG,
    • _CANSPI_CONFIG_MATCH_MSG_TYPE & _CANSPI_CONFIG_XTD_MSG.
    See CANSPI_CONFIG_FLAGS constants.
Returns

Nothing.

Requires

The CANSPI module must be in Config mode, otherwise the function will be ignored. 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
// set the appropriate filter mask and message type value
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);              // set CONFIGURATION mode (CANSPI1 module must be in config mode for mask settings)

// Set all B1 mask bits to 1 (all filtered bits are relevant):
// Note that -1 is just a cheaper way to write 0xFFFFFFFF.
// Complement will do the trick and fill it up with ones.
CANSPISetMask(_CANSPI_MASK_B1, -1, _CANSPI_CONFIG_MATCH_MSG_TYPE and _CANSPI_CONFIG_XTD_MSG);
Notes

None.

CANSPISetFilter

Prototype

procedure CANSPISetFilter(CAN_FILTER : as byte, val : longint, CANSPI_CONFIG_FLAGS : as byte);

Description

Configures message filter. The parameter value is bit-adjusted to the appropriate filter registers.

Parameters
  • CANSPI_FILTER: CAN module filter number. Valid values: CANSPI_FILTER constants. See CANSPI_FILTER constants.
  • val: filter register value. This value is bit-adjusted to appropriate filter registers
  • CANSPI_CONFIG_FLAGS: selects type of message to filter. Valid values: _CANSPI_CONFIG_STD_MSG and _CANSPI_CONFIG_XTD_MSG. See CANSPI_CONFIG_FLAGS constants.
Returns

Nothing.

Requires

The CANSPI module must be in Config mode, otherwise the function will be ignored. 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
// set the appropriate filter value and message type
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);                  // set CONFIGURATION mode (CANSPI module must be in config mode for filter settings)

// Set id of filter B1_F1 to 3 :
CANSPISetFilter(_CANSPI_FILTER_B1_F1, 3, _CANSPI_CONFIG_XTD_MSG);
Notes

None.

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 flags are retrieved and stored to location provided by the CANSPI_RX_MSG_FLAGS parameter
Parameters
  • id: message identifier address
  • data: an array of bytes up to 8 bytes in length
  • dataLen: data length address
  • CANSPI_RX_MSG_FLAGS: message flags address. For message receive flags 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 CANSPIxSetOperationMode.

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_flags, 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_flags := 0;                                                // clear message flags
if (msg_rcvd = CANSPIRead(msg_id, data, data_len, rx_flags)) then
begin
  ...
end;
Notes

None.

CANSPIWrite

Prototype

function CANSPIWrite(id : longint; var Data_ : array[8] of byte; DataLen, CANSPI_TX_MSG_FLAGS : byte) : 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
var tx_flags : byte;
    data : array[8] of byte;
    msg_id : longint;
...
CANSPISetOperationMode(CANSPI_MODE_NORMAL,0xFF);                  // set NORMAL mode (CANSPI 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:

Copy Code To ClipboardCopy Code To Clipboard
const
    _CANSPI_MODE_BITS   : byte = $E0;   // Use this to access opmode  bits
    _CANSPI_MODE_NORMAL : byte = 0;
    _CANSPI_MODE_SLEEP  : byte = $20;
    _CANSPI_MODE_LOOP   : byte = $40;
    _CANSPI_MODE_LISTEN : byte = $60;
    _CANSPI_MODE_CONFIG : byte = $80;

CANSPI_CONFIG_FLAGS Constants

The CANSPI_CONFIG_FLAGS constants define flags related to the CANSPI module configuration. The functions CANSPIInitialize, CANSPISetBaudRate, CANSPISetMask and CANSPISetFilter expect one of these (or a bitwise combination) as their argument:

Copy Code To ClipboardCopy Code To Clipboard
const
    _CANSPI_CONFIG_DEFAULT        : byte  = $FF;   // 11111111

    _CANSPI_CONFIG_PHSEG2_PRG_BIT : byte  = $01;
    _CANSPI_CONFIG_PHSEG2_PRG_ON  : byte  = $FF;   // XXXXXXX1
    _CANSPI_CONFIG_PHSEG2_PRG_OFF : byte  = $FE;   // XXXXXXX0

    _CANSPI_CONFIG_LINE_FILTER_BIT : byte = $02;
    _CANSPI_CONFIG_LINE_FILTER_ON  : byte = $FF;   // XXXXXX1X
    _CANSPI_CONFIG_LINE_FILTER_OFF : byte = $FD;   // XXXXXX0X

    _CANSPI_CONFIG_SAMPLE_BIT      : byte = $04;
    _CANSPI_CONFIG_SAMPLE_ONCE     : byte = $FF;   // XXXXX1XX
    _CANSPI_CONFIG_SAMPLE_THRICE   : byte = $FB;   // XXXXX0XX

    _CANSPI_CONFIG_MSG_TYPE_BIT    : byte = $08;
    _CANSPI_CONFIG_STD_MSG         : byte = $FF;   // XXXX1XXX
    _CANSPI_CONFIG_XTD_MSG         : byte = $F7;   // XXXX0XXX

    _CANSPI_CONFIG_DBL_BUFFER_BIT  : byte = $10;
    _CANSPI_CONFIG_DBL_BUFFER_ON   : byte = $FF;   // XXX1XXXX
    _CANSPI_CONFIG_DBL_BUFFER_OFF  : byte = $EF;   // XXX0XXXX

    _CANSPI_CONFIG_MSG_BITS        : byte = $60;
    _CANSPI_CONFIG_ALL_MSG         : byte = $FF;   // X11XXXXX
    _CANSPI_CONFIG_VALID_XTD_MSG   : byte = $DF;   // X10XXXXX
    _CANSPI_CONFIG_VALID_STD_MSG   : byte = $BF;   // X01XXXXX
    _CANSPI_CONFIG_ALL_VALID_MSG   : byte = $9F;   // X00XXXXX

You may use bitwise and to form config byte out of these values. For example:

Copy Code To ClipboardCopy Code To Clipboard
init := _CANSPI_CONFIG_SAMPLE_THRICE and
       _CANSPI_CONFIG_PHSEG2_PRG_ON and
       _CANSPI_CONFIG_STD_MSG       and
       _CANSPI_CONFIG_DBL_BUFFER_ON and
       _CANSPI_CONFIG_VALID_XTD_MSG and
       _CANSPI_CONFIG_LINE_FILTER_OFF;
...
CANSPIInitialize(1, 1, 3, 3, 1, init);   // initialize CANSPI

CANSPI_TX_MSG_FLAGS Constants

CANSPI_TX_MSG_FLAGS are flags related to transmission of a CANSPI message:

Copy Code To ClipboardCopy Code To Clipboard
 const
    _CANSPI_TX_PRIORITY_BITS : byte = $03;
    _CANSPI_TX_PRIORITY_0    : byte = $FC;   // XXXXXX00
    _CANSPI_TX_PRIORITY_1    : byte = $FD;   // XXXXXX01
    _CANSPI_TX_PRIORITY_2    : byte = $FE;   // XXXXXX10
    _CANSPI_TX_PRIORITY_3    : byte = $FF;   // XXXXXX11

    _CANSPI_TX_FRAME_BIT     : byte  = $08;
    _CANSPI_TX_STD_FRAME     : byte  = $FF;    // XXXXX1XX
    _CANSPI_TX_XTD_FRAME     : byte  = $F7;    // XXXXX0XX

    _CANSPI_TX_RTR_BIT       : byte = $40;
    _CANSPI_TX_NO_RTR_FRAME  : byte = $FF;    // X1XXXXXX
    _CANSPI_TX_RTR_FRAME     : byte = $BF;    // X0XXXXXX

You may use bitwise and to adjust the appropriate flags. For example:

Copy Code To ClipboardCopy Code To Clipboard
// form value to be used as sending message flag :
send_config := _CANSPI_TX_PRIORITY_0 and
              _CANSPI_TX_XTD_FRAME  and
              _CANSPI_TX_NO_RTR_FRAME;
...
CANSPIWrite(id, data, 1, send_config);

CANSPI_RX_MSG_FLAGS Constants

CANSPI_RX_MSG_FLAGS are flags related to reception of CANSPI message. If a particular bit is set then corresponding meaning is TRUE or else it will be FALSE.

Copy Code To ClipboardCopy Code To Clipboard
const
    _CANSPI_RX_FILTER_BITS  : byte = $07;   // Use this to access filter bits
    _CANSPI_RX_FILTER_1     : byte = $00;
    _CANSPI_RX_FILTER_2     : byte = $01;
    _CANSPI_RX_FILTER_3     : byte = $02;
    _CANSPI_RX_FILTER_4     : byte = $03;
    _CANSPI_RX_FILTER_5     : byte = $04;
    _CANSPI_RX_FILTER_6     : byte = $05;

    _CANSPI_RX_OVERFLOW     : byte = $08;   // Set if Overflowed else cleared
    _CANSPI_RX_INVALID_MSG  : byte = $10;   // Set if invalid else cleared
    _CANSPI_RX_XTD_FRAME    : byte = $20;   // Set if XTD message else cleared
    _CANSPI_RX_RTR_FRAME    : byte = $40;  // Set if RTR message else cleared
    _CANSPI_RX_DBL_BUFFERED : byte = $80;  // Set if this message was hardware double-buffered

You may use bitwise and to adjust the appropriate flags. For example:

Copy Code To ClipboardCopy Code To Clipboard
if (MsgFlag and _CANSPI_RX_OVERFLOW) <> 0 then
begin
  ...
  // Receiver overflow has occurred.
  // We have lost our previous message.
end;

CANSPI_MASK Constants

The CANSPI_MASK constants define mask codes. Function CANSPISetMask expects one of these as it's argument:

Copy Code To ClipboardCopy Code To Clipboard
const
    _CANSPI_MASK_B1 : byte = 0;
    _CANSPI_MASK_B2 : byte = 1;

CANSPI_FILTER Constants

The CANSPI_FILTER constants define filter codes. Functions CANSPISetFilter expects one of these as it's argument:

Copy Code To ClipboardCopy Code To Clipboard
const
    _CANSPI_FILTER_B1_F1 : byte = 0;
    _CANSPI_FILTER_B1_F2 : byte = 1;
    _CANSPI_FILTER_B2_F1 : byte = 2;
    _CANSPI_FILTER_B2_F2 : byte = 3;
    _CANSPI_FILTER_B2_F3 : byte = 4;
    _CANSPI_FILTER_B2_F4 : byte = 5;