SPI pins

From Pinguino-Wiki
Jump to: navigation, search

Contents

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

Clock Divider (SPI frequency)

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

Pins

Pinguino 1459 and 1xk50 SPI1 SPI2 SPI3 SPI4
Microchip Pinguino Microchip Pinguino Microchip Pinguino Microchip Pinguino
SDO RC7 Pin 7
SCK RB6 Pin 16
SDI RB4 Pin 14
CS or SS RC6 Pin 6
Pinguino x550 and x455 SPI1 SPI2 SPI3 SPI4
Microchip Pinguino Microchip Pinguino Microchip Pinguino Microchip Pinguino
SDO RC7 Pin 9
SCK RB1 Pin 1
SDI RB0 Pin 0
CS or SS RA5 Pin 17
Pinguino 45K50 SPI1 SPI2 SPI3 SPI4
Microchip Pinguino Microchip Pinguino Microchip Pinguino Microchip Pinguino
SDO RC7 Pin 23
SCK RB1 Pin 1
SDI RB0 Pin 0
CS or SS RA5 Pin 13
Pinguino 47J53 SPI1 SPI2 SPI3 SPI4
Microchip Pinguino Microchip Pinguino Microchip Pinguino Microchip Pinguino
SDO RC7 Pin 23 RB1 Pin 1
SCK RB4 Pin 4 RB2 Pin 2
SDI RB5 Pin 5 RB3 Pin 3
CS or SS RB6 Pin 6 RB0 Pin 0
Pinguino 32MX2x0 SPI1 SPI2 SPI3 SPI4
Microchip Pinguino Microchip Pinguino Microchip Pinguino Microchip Pinguino
SDO RA4 Pin 7 RB8 Pin 4
SCK RB14 Pin 1 RB15 Pin 0
SDI RB5 Pin 6 RB13 Pin 2
CS or SS RB7 Pin 5 RB9 Pin 3
Personal tools