Anda di halaman 1dari 2

SPI is a fluid standard for 3 or 4 wire, full duplex communications named by Motorola.

Most PIC devices support most common SPI modes. CCS provides a support library for taking advantage of both hardware and software based SPI functionality. For software support, see #USE SPI.

setup_spi( ) setup_spi2( )
Syntax: setup_spi (mode) setup_spi2 (mode) Parameters: mode may be: o SPI_MASTER, SPI_SLAVE, SPI_SS_DISABLED o SPI_L_TO_H, SPI_H_TO_L o SPI_CLK_DIV_4, SPI_CLK_DIV_16, SPI_CLK_DIV_64, SPI_CLK_T2 o SPI_SAMPLE_AT_END, SPI_XMIT_L_TO_H Constants from each group may be or'ed together with |. Returns: undefined Function: Initializes the Serial Port Interface (SPI). This is used for 2 or 3 wire serial devices that follow a common clock/data protocol. Examples: setup_spi(spi_master |spi_l_to_h |spi_clk_div_16 ); setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_DIV_BY_16);

spi_read( ) spi_read2( )
Syntax: value = spi_read (data) value = spi_read2 (data) Parameters: data is optional and if included is an 8 bit int. Returns:An 8 bit int Function: Return a value read by the SPI. If a value is passed to spi_read() the data will be clocked out and the data received will be returned. If no data is ready, spi_read() will wait for the data if A SLAVE or return the last DATA clocked in from spi_write. If this device is the master then either do a spi_write (data) followed by a spi_read() or do a spi_read (data). These both do the same thing and will generate a clock. If there is no data to send just do a SPI_READ(0) to get the clock. If this device is a slave then either call spi_read() to wait for the clock and data or use spi_data_is_in() to determine if data is ready. Examples: in_data = spi_read(out_data);

spi_write( ) spi_write2( )
Syntax: spi_write (value) spi_write2 (value) Parameters: value is an 8 bit int Function: Sends a byte out the SPI interface. This will cause 8 clocks to be generated. This function will write the value out to the SPI. At the same time data is clocked out data is clocked in and stored in a receive buffer. spi_read() may be used to read the buffer. Examples: spi_write( data_out ); data_in = spi_read();

spi_data_is_in( ) spi_data_is_in2( )
Syntax: result = spi_data_is_in() result = spi_data_is_in2()

Returns:0 (FALSE) or 1 (TRUE) Function: Returns TRUE if data has been received over the SPI. Examples: while ( !spi_data_is_in() && input(PIN_B2) ); If( spi_data_is_in() ) data = spi_read();

Como funciona la interfaz spi

Anda mungkin juga menyukai