User manual

mikroBasic PRO for PIC32
MikroElektronika
243
CANSPI Library
The SPI module is available with a number of the PIC32 MCUs. The mikroBasic PRO for PIC32 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 connement.
Faulty CAN data and remote frames are re-transmitted automatically, similar to the Ethernet.
CAN supports two message formats:
- Standard format, with 11 identier bits and
- Extended format, with 29 identier bits
Important:
- Consult the CAN standard about CAN bus termination resistance.
- An effective CANSPI communication speed depends on SPI and certainly is slower than “real” CAN.
- The library uses the SPI module for communication. User must initialize appropriate SPI module before using
the CANSPI Library.
- For MCUs with multiple SPI modules it is possible to initialize both of them and then switch by using the
SPI_Set_Active routine.
- Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before
utilizing this library.
- CANSPI module refers to mikroElektronika’s CANSPI Add-on board connected to SPI module of MCU.
Library Dependency Tree
External dependencies of CANSPI Library
The following variables must be
dened in all projects using CANSPI
Library:
Description: Example:
dim CanSpi_CS as sbit sfr
external
Chip Select line.
dim CanSpi_CS as sbit at LATF0_bit
dim CanSpi_Rst as sbit sfr
external
Reset line.
dim CanSpi_Rst as sbit at LATF1_bit
dim CanSpi_CS_Direction as
sbit sfr external
Direction of the Chip Select pin.
dim CanSpi_CS_Direction as sbit at
TRISF0_bit
dim CanSpi_Rst_Direction as
sbit sfr external
Direction of the Reset pin.
dim CanSpi_Rst_Direction as sbit at
TRISF1_bit