17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PreProcessor<br />

CLOCK_HIGH=n High time of clock in us (not needed if BAUD= is<br />

used). (default=0)<br />

CLOCK_LOW=n Low time of clock in us (not needed if BAUD= is<br />

used). (default=0)<br />

DI=pin<br />

Optional pin for incoming data.<br />

DO=pin<br />

Optional pin for outgoing data.<br />

CLK=pin<br />

Clock pin.<br />

MODE=n<br />

The mode to put the SPI bus.<br />

ENABLE=pin<br />

Optional pin to be active during data transfer.<br />

LOAD=pin<br />

Optional pin to be pulsed active after data is<br />

transferred.<br />

DIAGNOSTIC=pin Optional pin to the set high when data is sampled.<br />

SAMPLE_RISE<br />

Sample on rising edge.<br />

SAMPLE_FALL Sample on falling edge (default).<br />

BITS=n<br />

Max number of bits in a transfer. (default=32)<br />

SAMPLE_COUNT=n Number of samples to take (uses majority vote).<br />

(default=1<br />

LOAD_ACTIVE=n Active state for LOAD pin (0, 1).<br />

ENABLE_ACTIVE=n Active state for ENABLE pin (0, 1). (default=0)<br />

IDLE=n<br />

Inactive state for CLK pin (0, 1). (default=0)<br />

ENABLE_DELAY=n Time in us to delay after ENABLE is activated.<br />

(default=0)<br />

DATA_HOLD=n Time between data change and clock change<br />

LSB_FIRST<br />

LSB is sent first.<br />

MSB_FIRST<br />

MSB is sent first. (default)<br />

STREAM=id<br />

Specify a stream name for this protocol.<br />

SPI1 Use the hardware pins for SPI Port 1<br />

SPI2 Use the hardware pins for SPI Port 2<br />

FORCE_HW<br />

Use the pic hardware SPI.<br />

NOINIT<br />

Don't initialize the hardware SPI Port<br />

Purpose:<br />

The SPI library contains functions to implement an SPI bus. After setting all of the<br />

proper parameters in #USE SPI, the spi_xfer() function can be used to both<br />

transfer and receive data on the SPI bus.<br />

The SPI1 and SPI2 options will use the SPI hardware onboard the PIC. The most<br />

common pins present on hardware SPI are: DI, DO, and CLK. These pins don’t<br />

need to be assigned values through the options; the compiler will automatically<br />

assign hardware-specific values to these pins. Consult your PIC’s data sheet as to<br />

where the pins for hardware SPI are. If hardware SPI is not used, then software<br />

SPI will be used. Software SPI is much slower than hardware SPI, but software<br />

SPI can use any pins to transfer and receive data other than just the pins tied to<br />

the PIC’s hardware SPI pins.<br />

The MODE option is more or less a quick way to specify how the stream is going<br />

to sample data. MODE=0 sets IDLE=0 and SAMPLE_RISE. MODE=1 sets<br />

IDLE=0 and SAMPLE_FALL. MODE=2 sets IDLE=1 and SAMPLE_FALL.<br />

MODE=3 sets IDLE=1 and SAMPLE_RISE. There are only these 4 MODEs.<br />

SPI cannot use the same pins for DI and DO. If needed, specify two streams: one<br />

to send data and another to receive data.<br />

145

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!