|
Synopsis
int sub_spi_config( sub_handle hndl, int cfg_set, int* cfg_get )
Configure SUB-20 SPI module or read current configuration. If *cfg_get is NULL function will configure SPI according to the cfg_set parameter. Otherwise it will read current SPI configuration into *cfg_get
Parameters
| • | cfg_set - Desired SPI configuration. This parameter is effective only if *cfg_get is NULL. cfg_set should be assembled as a combination of below flags |
SPI_ENABLE
|
Enable SUB-20 SPI module.
|
SPI_SLAVE
|
SPI module is in Slave mode. sub_spi_transfer can work only when SPI module is in Master mode
|
|
SPI_CPOL_RISE
|
SCK is low when idle. See SPI Polarity and Phase explanations
|
SPI_CPOL_FALL
|
SCK is high when idle. See SPI Polarity and Phase explanations
|
|
SPI_SMPL_SETUP
|
Sample data on leading SCK edge, setup on trailing. See SPI Polarity and Phase
|
SPI_SETUP_SMPL
|
Setup data on leading SCK edge, sample on trailing. See SPI Polarity and Phase
|
|
|
Below flags are relevant only for SPI master mode (SPI_SLAVE not set)
|
|
SPI_LSB_FIRST
|
Transmit LSB first
|
SPI_MSB_FIRST
|
Transmit MSB first
|
|
|
SPI_CLK_8MHZ
|
SPI SCK frequency 8 MHz
|
SPI_CLK_4MHZ
|
SPI SCK frequency 4 MHz
|
SPI_CLK_2MHZ
|
SPI SCK frequency 2 MHz
|
SPI_CLK_1MHZ
|
SPI SCK frequency 1 MHz
|
SPI_CLK_500KHZ
|
SPI SCK frequency 500 KHz
|
SPI_CLK_250KHZ
|
SPI SCK frequency 250 KHz
|
SPI_CLK_125KHZ
|
SPI SCK frequency 125 KHz
|
Beginning from FW version 0.3.3 and library version 0.1.12.25 lower SPI frequencies (down to 4KHz) are supported for SPI Master transfer with sub_spi_transfer function. Special SPI_CLK_HZ(FHZ) macro defined in libsub.h, where FHZ parameter denotes SPI frequency in Hz. Supported frequencies range is 100.000Hz .. 4000Hz. Exact frequency may differ from requested due to integer rounding in division.
SPI_CLK_HZ(FHZ)
|
SPI SCK frequency 100.000Hz .. 4000Hz
|
| • | *cfg_get - Pointer to store current configuration read from SUB-20 device or NULL |
Return value
On success function returns 0. Otherwise error code.
Example
/* Read current SPI configuration */
sub_spi_config( hndl, 0, &spi_config );
/* Configure SPI */
sub_spi_config( hndl, SPI_ENABLE|SPI_CPOL_RISE|SPI_SMPL_SETUP|SPI_MSB_FIRST|SPI_CLK_4MHZ, 0 );
/* Disable SPI */
sub_spi_config( hndl, 0, 0 );
Compatibility
SPI_CLK_HZ(FHZ)
|
FW version
|
0.3.3 or grater
|
Library version
|
0.1.12.25 or grater
|
|