User`s manual

mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
SPI (Serial Peripheral Interface) module is available with a number of PIC MCU
models. Set of library procedures and functions is listed below to provide comfort-
able work with external CAN modules (such as MCP2515 or MCP2510) via SPI.
CANSPI routines are supported by any PIC MCU model that has SPI interface on
portc. Also, CS pin of MCP2510 or MCP2515 must be connected to RC0 pin.
Example of HW connection is given at the end of the chapter.
The Controller Area Network module is a serial interface, useful for communicat-
ing with other peripherals or microcontrollers. Details about CAN can be found in
appropriate literature and on mikroElektronika Web site. MCP2515 or MCP2510
are modules that enable any chip with SPI interface to communicate over CAN
bus.
Following routines should be considered a driver for CANSPI (CAN via SPI mod-
ule) on PIC MCUs.
MikroElektronika:
Development
tools
-
Books
-
Compilers
mikroBASIC
making it simple...
125
page
CANSPI Library
sub procedure CANSPISetOperationMode(dim mode as byte, dim WAIT as byte)
sub function CANSPIGetOperationMode as byte
sub procedure CANSPIInitialize(dim SJW as byte, dim BRP as byte, dim PHSEG1 as byte,
dim PHSEG2 as byte, dim PROPSEG as byte,dim CAN_CONFIG_FLAGS as byte)
sub procedure CANSPISetBaudRate(dim SJW as byte, dim BRP as byte, dim PHSEG1 as byte,
dim PHSEG2 as byte, dim PROPSEG as byte,dim CAN_CONFIG_FLAGS as byte)
sub procedure CANSPISetMask(dim CAN_MASK as byte, dim val as longint, dim CAN_CONFIG_FLAGS as
byte)
sub procedure CANSPISetFilter(dim CAN_FILTER as byte, dim val as longint,
dim CAN_CONFIG_FLAGS as byte)
sub function RegsToCANSPIID(dim byref ptr as byte, dim CAN_CONFIG_FLAGS as byte) as longint
sub procedure CANSPIIDToRegs(dim byref ptr as byte, dim val as longint,
dim CAN_CONFIG_FLAGS as byte)
sub function CANSPIwrite(dim id as longint, dim byref Data as byte[8], dim DataLen as byte,
dim CAN_TX_MSG_FLAGS as byte) as byte
sub function CANSPIread(dim byref id as longint, dim byref Data as byte[8],
dim byref DataLen as byte, dim byref CAN_RX_MSG_FLAGS as byte) as byte