SPIIN
 
Syntax


void SPIIN (int CS_pin,int in_pin,int clk_pin,int out_pin, int out1, int out2, int out3, int cnt, char *InputList);

Description


SPIIN supports the loosely defined serial protocol used by a variety of manufacturers.  The desired device is selected by asserting CS_pin LOW.  If there is no CS_pin , the value should be set to -1.

In the simplest case, in_pin is used to input data clocked by clk_pin, to fill the character array InputList with cnt bytes.

In bi-directional cases, out1..out3 byte values will be output on out_pin before reading the InputList . If not used, those should be set to -1.  It is also allowable to have in_pin equal to out_pin , in which case that pin will be driven for the out1..out3 and then converted to an input for in_pin .

Data is shifted in LSB first and each element of the InputList is filled with a byte of data. To use negative edge clocks or MSB first, the default SPImode may be changed.

Data is shifted in at 600 Kbits/sec.

Example

   case 42:   // check MicroMega FPU status
                   // clock on pin 15 and bi-directional data on 14, no CS used
    SPImode = 0; // FPU uses MSB first -- positive clock
    for (i=0; i<10; i++) shortMessage[i]= 0xFF;
    shortMessage [i] = 0;
    SPIOUT (-1,14,15,11,shortMessage);  // reset FPU
    WAIT (10);     
        
    shortMessage [0] = 0xF0;    // sync character
    SPIOUT (-1,14,15,1,shortMessage);  // sync FPU
    save_time = TIMER;
    while ((TIMER - save_time) < 15) ;     // wait 15 uSec
    SPIIN (-1,14,15, -1,-1,-1,-1, 1,shortResponse);  // get 1 byte status back
     
    if (shortResponse[0] != 0x5C) {
     printf("%x No FPU found\n",shortResponse[0]);
     break;
    }
    printf("FPU found\n");

See also