#USE SPI ()

Some of CCS's most powerful libraries have been the RS-232 and I2C libraries, which give users the flexibility of using multiple RS-232 and I2C ports at once using any set of general purpose I/O pins, and not tying the user to only using the hardware peripheral. SPI libraries are included to give the user: use of any general purpose I/O pins, clocking configuration, any number of data bits, streams, clock rate and more!

 

/*
The #use SPI configures the SPI port. Here is a simple configuration:
*/

#use SPI(
   DO = PIN_B0,
   DI = PIN_B1,
   CLK = PIN_B2,
   baud = 100000,
   BITS = 8,
   LSB_FIRST,
   SAMPLE_RISE,
   stream = SPI_PORT0
)

/*
Read a byte of data to a 9356 external EEPROM using this new SPI stream
*/

void Read9356(long address, int data)
{
   output_high(EEPROM_9356_SELECT);
   SPI_XFER(SPI_PORT0, 0x18);
   SPI_XFER(SPI_PORT0, address);
   data=SPI_XFER(SPI_PORT0, 0);
   output_low(EEPROM_9356_SELECT);
}