User manual

mikroPascal PRO for PIC32
MikroElektronika
385
Soft_SPI_Read
Soft_SPI_Write
Prototype
function Soft_SPI_Read(data_ : byte) : byte;
Description This routine performs 3 operations simultaneously. It provides clock for the Software SPI bus, reads
a byte and sends a byte.
Parameters - sdata: data to be sent.
Returns Byte received via the SPI bus.
Requires Soft SPI must be initialized before using this function. See Soft_SPI_Init routine.
Example
var data_read, data_send : byte;
...
// Read a byte and assign it to data_read variable
// (data_send byte will be sent via SPI during the Read operation)
data_read := Soft_SPI_Read(data_send);
Notes None
Prototype
procedure Soft_SPI_Write(sdata : byte);
Description This routine sends one byte via the Software SPI bus.
Parameters - sdata: data to be sent.
Returns Nothing.
Requires Soft SPI must be initialized before using this function. See Soft_SPI_Init.
Example
// Write a byte to the Soft SPI bus
Soft_SPI_Write(0xAA);
Notes None
Library Example
This code demonstrates using library routines for Soft_SPI communication. Also, this example demonstrates working
with max7219. Eight 7 segment displays are connected to MAX7219. MAX7219 is connected to SDO, SDI, SCK pins
are connected accordingly.
Copy Code To Clipboard
// DAC module connections
var Chip_Select : sbit at LATD0_bit;
SoftSpi_CLK : sbit at LATD6_bit;
SoftSpi_SDI : sbit at RD2_bit;
SoftSpi_SDO : sbit at LATD3_bit;
var Chip_Select_Direction : sbit at TRISD0_bit;
SoftSpi_CLK_Direction : sbit at TRISD6_bit;
SoftSpi_SDI_Direction : sbit at TRISD2_bit;
SoftSpi_SDO_Direction : sbit at TRISD3_bit;
// End DAC module connections