User manual
mikroPascal PRO for PIC32
MikroElektronika
241
CANSPI Library
The SPI module is available with a number of the PIC32 MCUs. The mikroPascal 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, selfchecking and fault connement.
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 dened by the standard is 200Kbit/s. Cables used are shielded twisted pairs.
CAN supports two message formats:
- Standard format, with 11 identier bits and
- Extended format, with 29 identier 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 SPI Graphic Lcd 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.
Library Dependency Tree
External dependencies of CANSPI Library
The following variables must be
dened in all projects using CANSPI
Library:
Description: Example:
var CanSpi_CS : sbit; sfr;
external;
Chip Select line.
var CanSpi_CS : sbit at
LATF0_bit;
var CanSpi_Rst : sbit; sfr;
external;
Reset line.
var CanSpi_Rst : sbit at
LATF1_bit;
var CanSpi_CS_Direction :
sbit; sfr; external;
Direction of the Chip Select pin.
var CanSpi_CS_Direction :
sbit at TRISF0_bit;
var CanSpi_Rst_Direction :
sbit; sfr; external;
Direction of the Reset pin.
var CanSpi_Rst_Direction :
sbit at TRISF1_bit;