User manual

mikroC PRO for dsPIC
MikroElektronika
483
Soft_SPI_Read
Soft_SPI_Write
Prototype
unsigned short Soft_SPI_Read(char sdata);
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
unsigned short data_read;
char data_send;
...
// 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
void Soft_SPI_Write(char sdata);
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
sbit Chip_Select at LATF0_bit;
sbit SoftSpi_CLK at LATF6_bit;
sbit SoftSpi_SDI at RF4_bit;
sbit SoftSpi_SDO at LATF3_bit;
sbit Chip_Select_Direction at TRISF0_bit;
sbit SoftSpi_CLK_Direction at TRISF6_bit;
sbit SoftSpi_SDI_Direction at TRISF4_bit;
sbit SoftSpi_SDO_Direction at TRISF3_bit;
// End DAC module connections