SPI Slave

Top  Previous  Next
Got to SUB-20 page

Configuration

To use SUB-20 in SPI slave mode following should be done:

Configure SPI module with sub_spi_config. Make sure to set SPI_SLAVE flag.

Connect SPI module to FIFO with sub_fifo_config. FIFO_SELECT_SPI must be set.

If required, write data to FIFO with sub_fifo_write. This data will be read by external SPI master.

If required, read data from FIFO with sub_fifo_read. This will be data written by external SPI master.

 

Example

Below is an example to exchange 12 bytes with SPI master:

 

sub_spi_config( hndl, SPI_ENABLE|SPI_SLAVE|SPI_CPOL_RISE|SPI_SMPL_SETUP, 0 );

sub_fifo_config( hndl, FIFO_SELECT_SPI );

sub_fifo_write( hndl, "Hello Master", 12, 100 );

read_sz=0;

while( read_sz < 12 )

{

  rc = sub_fifo_read( hndl, in_buff, 64, 10000 ); /* wait 10 sec */

  if( rc < 0 )

    return rc;   /* error */

  read_sz += rc;

}

 

Slave Select

SUB-20 SPI Slave module use SS0 pin as slave select. SS0 must be pulled low by external SPI master to enable SUB-20 SPI module functionality. When SS0 is held low, the SPI is activated, and MISO becomes an output. All other pins are inputs. When SS is driven high, all pins are inputs, and the SPI is passive.