SPI pins

SPI
The Serial Peripheral Interface (SPI) bus is a synchronous serial communication interface specification used for short distance communication, primarily in embedded systems. The interface was developed by Motorola and has become a de facto standard. Typical applications include Secure Digital cards and liquid crystal displays.

Wikipedia

Libraries SD, LedControl, ST7735, etc use SPI communication.

Keywords
SPISW : SPI Software SPI1 : SPI Module #1 SPI2 : SPI Module #2 SPI3 : SPI Module #3 SPI4 : SPI Module #4

Init. Example
SPI Sofware : SPI.setBitOrder(SPISW, SPI_MSBFIRST); SPI.begin(SPISW, sdo, sck, cs);

SPI Hardware : SPI.setMode(SPI1, SPI_MASTER); SPI.setDataMode(SPI1, SPI_MODE1); SPI.setClockDivider(SPI1, SPI_CLOCK_DIV4); SPI.begin(SPI1);

Bit order
SPI_MSBFIRST : Most Significant Bit (bit 4 to 7) send first SPI_LSBFIRST : Less Significant Bit (bit 0 to 3) send first

Mode
SPI_MASTER  : Mater Mode, data width is 8-bit SPI_MASTER8 : same as SPI_MASTER SPI_MASTER16 : Master Mode, data width is 16-bit SPI_MASTER32 : Master Mode, data width is 32-bit (PIC32 only) SPI_SLAVE   : Slave Mode

Data Mode
SPI_MODE0 : clock idle state low, data transmitted on rising edge SPI_MODE1 : clock idle state low, data transmitted on falling edge SPI_MODE2 : clock idle state high, data transmitted on rising edge SPI_MODE3 : clock idle state high, data transmitted on falling edge

8-bit
SPI_CLOCK_DIV4  : CPU Clock divided by 4 SPI_CLOCK_DIV8  : CPU Clock divided by 8 SPI_CLOCK_DIV16 : CPU Clock divided by 16 SPI_CLOCK_DIV64 : CPU Clock divided by 64 SPI_CLOCK_TIMER2 : SPI freq. = Timer2 freq.

PBCLOCK = FOSC/4, so

SPI_CLOCK_DIV4  = SPI_PBCLOCK_NODIV SPI_CLOCK_DIV8  = SPI_PBCLOCK_DIV2 SPI_CLOCK_DIV16 = SPI_PBCLOCK_DIV4 SPI_CLOCK_DIV64 = SPI_PBCLOCK_DIV16

32-bit
SPI_PBCLOCK_DIV2   : Peripheral clock freq. divided by 2 SPI_PBCLOCK_DIV4   : divided by 4 SPI_PBCLOCK_DIV8   : divided by 8 SPI_PBCLOCK_DIV16  : divided by 16 SPI_PBCLOCK_DIV32  : divided by 32 SPI_PBCLOCK_DIV64  : divided by 64 SPI_PBCLOCK_DIV128 : divided by 128 SPI_PBCLOCK_DIV256 : divided by 256 SPI_PBCLOCK_DIV512 : divided by 512 SPI_PBCLOCK_DIV1024 : divided by 1024