User manual

mikroBasic PRO for PIC32
MikroElektronika
393
Software SPI Library
The mikroBasic PRO for PIC32 provides routines for implementing Software SPI communication. These routines are
hardware independent and can be used with any MCU. The Software SPI Library provides easy communication with
other devices via SPI: A/D converters, D/A converters, MAX7219, LTC1290, etc.
Library conguration:
- SPI to Master mode
- Clock value = 20 kHz.
- Data sampled at the middle of interval.
- Clock idle state low.
- Data sampled at the middle of interval.
- Data transmitted at low to high edge.
The library congures SPI to the master mode, clock = 20kHz, data sampled at the middle of interval, clock idle state
low and data transmitted at low to high edge.
Important: The Software SPI library implements time-based activities, so interrupts need to be disabled when using it.
The following variables must be dened
in all projects using Software SPI
Library:
Description: Example:
dim SoftSpi_SDI as sbit sfr
external
Data In line.
dim SoftSpi_SDI as sbit at RF2_bit
dim SoftSpi_SDO as sbit sfr
external
Data Out line.
dim SoftSpi_SDO as sbit at LATF3_bit
dim SoftSpi_CLK as sbit sfr
external
Clock line.
dim SoftSpi_CLK as sbit at LATF6_bit
dim SoftSpi_SDI_Direction as
sbit sfr external
Direction of the Data In pin.
dim SoftSpi_SDI_Direction as sbit at
TRISF2_bit
dim SoftSpi_SDO_Direction as
sbit sfr external
Direction of the Data Out pin
dim SoftSpi_SDO_Direction as sbit at
TRISF3_bit
dim SoftSpi_CLK_Direction as
sbit sfr external
Direction of the Clock pin.
dim SoftSpi_CLK_Direction as sbit at
TRISF6_bit
External dependencies of Software SPI Library
Library Routines
- Soft_SPI_Init
- Soft_SPI_Read
- Soft_SPI_Write