Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
mikroC PRO for PIC32
MikroElektronika
423
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 LATD0_bit;
sbit SoftSpi_CLK at LATD6_bit;
sbit SoftSpi_SDI at RD2_bit;
sbit SoftSpi_SDO at LATD3_bit;
sbit Chip_Select_Direction at TRISD0_bit;
sbit SoftSpi_CLK_Direction at TRISD6_bit;
sbit SoftSpi_SDI_Direction at TRISD2_bit;
sbit SoftSpi_SDO_Direction at TRISD3_bit;
// End DAC module connections