The ESP8266 has two hardware SPI modules. Espressif have named these SPI and HSPI.
SPI: This SPI module is capable of quad data channels and has 3x chip select pins available. However, it is already in use on 99.9% of modules where the operational code is loaded off a flash rom chip. It is incredibly difficult to use this for other devices at the same time without constant interruption and I don’t recommend it. You can, however, mux the HSPI pins onto the same ones as the SPI module. The SPI module will take over control of the pins when it needs access (so you’re not guaranteed your HSPI operation all the time). I won’t be covering anything more on the SPI module any time soon though. HSPI is where it’s at for simplicity.
HSPI: Presumably this is meant to stand for HardwareSPI, but you can think of it as the User SPI. The pinout required is below.
|Pin Name||GPIO #||HSPI Function|
|MTDO||GPIO15||CS / SS|
Pin Name is the one given in the datasheet. Note that the MTCK (which is a clock signal for something else) is NOT the clock for the HSPI! Same with the MTDO (data out) pin. It’s actually the HSPI Chip Select (or Slave Select). Easy to be confused 🙂
Note: GPIO15 needs to be tied to GND when booting from the onboard SPI flash (see below table). Just use a suitable pull down resistor (4.7k or something) so the pin can still properly function as a chip select. Do not connect it directly to GND!
|L||L||H||UART||Download code from UART|
|L||H||H||Flash||Boot from SPI Flash|
|H||x||x||SDIO||Boot from SD-card|
With the HSPI bus wired correctly to your SPI slave device, you can get started using the SDK code. See my other posts for more information on controlling the HSPI hardware.