sub_spi_transfer |
Top Previous Next |
Got to SUB-20 page |
Synopsis int sub_spi_transfer( sub_handle hndl, char* out_buf, char* in_buf, int sz, int ss_config )
Perform SPI master transaction. Depending on out_buf and in_buf parameters transaction can be either read (out_buf==0), write (in_buf==0) or read-write ( both in_buf and out_buf are non zero). Parameters •out_buf - Output data buffer or NULL. If NULL there will be no write transaction and MOSI pin will stay unchanged. •in_buf - Input buffer to store read data or NULL. If NULL there will be no read transaction and data on MISO pin will be ignored. •sz - Transaction size •ss_config - Determines selection and operation of SS pin. ss_config value must be created with macro SS_CONF(SS_N,SS_MODE) , where SS_N is SS pin number and SS_MODE is one of the following flags:
If ss_config is zero there will be no SS activity (changes). Return value On success function returns 0. Otherwise error code. Example /* Write 10 bytes. Use SS0 low */ rc = sub_spi_transfer( hndl, out, 0, 10, SS_CONF(0,SS_LO) );
/* Transfer 10 bytes out and 10 bytes in. Use SS2 high */ rc = sub_spi_transfer( hndl, out, in, 10, SS_CONF(2,SS_HI) );
/* Read 10 bytes. No SS */ rc = sub_spi_transfer( hndl, 0, in, 10, 0 );
|