User manual
mikroBasic PRO for PIC32
MikroElektronika
395
Soft_SPI_Read
Soft_SPI_Write
Prototype
sub function Soft_SPI_Read(dim data_ as byte) as 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
dim data_read, data_send as 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
sub procedure Soft_SPI_Write(dim data_ as 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($AA)
Notes None
Library Example
This code demonstrates using library routines for Soft_SPI communication. Also, this example demonstrates working
with Microchip’s MCP4921 12-bit D/A converter.
Copy Code To Clipboard
// DAC module connections
dim Chip_Select as sbit at LATD0_bit
SoftSpi_CLK as sbit at LATD6_bit
SoftSpi_SDI as sbit at RD2_bit
SoftSpi_SDO as sbit at LATD3_bit
dim Chip_Select_Direction as sbit at TRISD0_bit
SoftSpi_CLK_Direction as sbit at TRISD6_bit
SoftSpi_SDI_Direction as sbit at TRISD2_bit
SoftSpi_SDO_Direction as sbit at TRISD3_bit
// End DAC module connections