SPI
About
For some APIs, the reference to be used is the same as the Arduino Core.
Arduino API Reference
Example
To get started with SPI, you can try:
SPI Multiple Buses
/* The ESP32 has four SPi buses, however as of right now only two of * them are available to use, HSPI and VSPI. Simply using the SPI API * as illustrated in Arduino examples will use VSPI, leaving HSPI unused. * * However if we simply initialize two instance of the SPI class for both * of these buses both can be used. However when just using these the Arduino * way only will actually be outputting at a time. * * Logic analyzer capture is in the same folder as this example as * "multiple_bus_output.png" * * created 30/04/2018 by Alistair Symonds */#include<SPI.h>// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus#ifdef ALTERNATE_PINS#define VSPI_MISO 2#define VSPI_MOSI 4#define VSPI_SCLK 0#define VSPI_SS 33#define HSPI_MISO 26#define HSPI_MOSI 27#define HSPI_SCLK 25#define HSPI_SS 32#else#define VSPI_MISO MISO#define VSPI_MOSI MOSI#define VSPI_SCLK SCK#define VSPI_SS SS#define HSPI_MISO 12#define HSPI_MOSI 13#define HSPI_SCLK 14#define HSPI_SS 15#endif#if !defined(CONFIG_IDF_TARGET_ESP32)#define VSPI FSPI#endifstaticconstintspiClk=1000000;// 1 MHz//uninitialized pointers to SPI objectsSPIClass*vspi=NULL;SPIClass*hspi=NULL;voidsetup(){//initialize two instances of the SPIClass attached to VSPI and HSPI respectivelyvspi=newSPIClass(VSPI);hspi=newSPIClass(HSPI);//clock miso mosi ss#ifndef ALTERNATE_PINS//initialize vspi with default pins//SCLK = 18, MISO = 19, MOSI = 23, SS = 5vspi->begin();#else//alternatively route through GPIO pins of your choicevspi->begin(VSPI_SCLK,VSPI_MISO,VSPI_MOSI,VSPI_SS);//SCLK, MISO, MOSI, SS#endif#ifndef ALTERNATE_PINS//initialize hspi with default pins//SCLK = 14, MISO = 12, MOSI = 13, SS = 15hspi->begin();#else//alternatively route through GPIO pinshspi->begin(HSPI_SCLK,HSPI_MISO,HSPI_MOSI,HSPI_SS);//SCLK, MISO, MOSI, SS#endif//set up slave select pins as outputs as the Arduino API//doesn't handle automatically pulling SS lowpinMode(vspi->pinSS(),OUTPUT);//VSPI SSpinMode(hspi->pinSS(),OUTPUT);//HSPI SS}// the loop function runs over and over again until power down or resetvoidloop(){//use the SPI busesspiCommand(vspi,0b01010101);// junk data to illustrate usagespiCommand(hspi,0b11001100);delay(100);}voidspiCommand(SPIClass*spi,bytedata){//use it as you would the regular arduino SPI APIspi->beginTransaction(SPISettings(spiClk,MSBFIRST,SPI_MODE0));digitalWrite(spi->pinSS(),LOW);//pull SS slow to prep other end for transferspi->transfer(data);digitalWrite(spi->pinSS(),HIGH);//pull ss high to signify end of data transferspi->endTransaction();}