GNU Free Documentation License . .

Serial Peripheral Interface

: ,
SPI single slave.svg

SPI (. Serial Peripheral Interface, SPI bus  , SPI)  , Motorola . SPI (. four-wire) .

(. standard serial port), SPI , , (). () . - . , « » (. chip select) . , , SPI.

SPI :

  • MOSI SI  , (. Master Out Slave In). .
  • MISO SO  , (. Master In Slave Out). .
  • SCLK SCK  (. Serial Clock). .
  • CS SS  , (. Chip Select, Slave Select).

[]

SPI . «chip select» ( ) ( - ), , , . chip select. , .

unsigned char SPIBitBang8BitsMode0(unsigned char byte)
{       
    unsigned char bit;
 
    for (bit = 0; bit < 8; bit++) {
        /*  MOSI      */
        if (byte & 0x80)
            SETMOSI();
        else
            CLRMOSI();
        byte <<= 1;
 
        /*          */
        SPIDELAY(SPISPEED/2);
        SETCLK();
 
        /*          */
        SPIDELAY(SPISPEED/2);
 
        /*  MISO on trailing edge */
        byte |= READMISO();
        CLRCLK();
    }
 
    return byte;
}

[]