The ESP32 contains 4 SPI bus hosts called `SPI`, `SPI1`, `HSPI`, and `VSPI`. `SPI` is locked to flash communication and is not available for the application. `SPI1` is currently also tied to flash support, but might be available in the future. Applications can currently only use the `HSPI` and `VSPI` hosts.
The host signals can be mapped to any suitable GPIO pins.
The API on ESP32 differs from the API on ESP8266. For backwards compatibility please refer to [`lua_compat/spi_compat.lua`](../../../lua_compat/spi_compat.lua).
-`dma` set DMA channel (1 or 2) or disable DMA (0), defaults to 1 if omitted.
Enabling DMA allows sending and receiving an unlimited amount of bytes but has restrictions in halfduplex mode (see [`spi.master:device()`](#spimasterdevice)).
Disabling DMA limits a transaction to 32 bytes max.
Close the bus host. This fails if there are still devices registered on this bus.
!!! caution
The bus is also closed when the bus master object is automatically destroyed during garbage collection. Registered devices inherently prevent garbage collection of the bus master object.
#### Syntax
`busmaster:close()`
#### Parameters
none
#### Returns
`nil`
## spi.master:device()
Adds a device on the given master bus. Up to three devices per bus are supported.
Due to restrictions of the ESP IDF, halfduplex mode does not support DMA with both MOSI and MISO phases. Disable DMA during the call to [`spi.master()`](#spimaster) in this case and ensure that transaction data is not larger than 32 bytes.