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:

 

SS_H

SS goes high and stays high during and after transaction

SS_HL

SS goes high and stays high during first byte transfer, after that it goes low

SS_HHL

SS goes high and stays high during first 2 bytes transfer, after that it goes low

SS_HHHL

SS goes high and stays high during first 3 bytes transfer, after that it goes low

SS_HHHHL

SS goes high and stays high during first 4 bytes transfer, after that it goes low

SS_HI

SS goes high and stays high during entire transfer, after that it goes low



SS_L

SS goes low and stays low during and after transaction

SS_LH

SS goes low and stays low during first byte transfer, after that it goes high

SS_LLH

SS goes low and stays low during first 2 bytes transfer, after that it goes high

SS_LLLH

SS goes low and stays low during first 3 bytes transfer, after that it goes high

SS_LLLLH

SS goes low and stays low during first 4 bytes transfer, after that it goes high

SS_LO

SS goes low and stays low during entire transfer, after that it goes high



SS_HiZ

SS stays in HiZ mode (Except SS0)

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 );