What are ESP32 SPI Ports for Micropython SPI(1)?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
choies
Posts: 2
Joined: Sat Jan 30, 2016 11:06 am

What are ESP32 SPI Ports for Micropython SPI(1)?

Post by choies » Sat May 20, 2017 4:23 pm

I make bin files for ESP32 module( ESP-WROOM-32)
Now I would like to test hardware SPI function using Micropython.

Please let me know the Hardware SPI port in ESP32 module( ESP-WROOM-32) for Micropython code?

For example.
1) SPI(1)
SPI_MISO = HSPIQ(GPIO12)
SPI_MOSI = HSPID(GPIO13)
SPI_CLK = HSPICLK(GPIO14)
SPI_CS = HSPICS0(GPIO15)

Thanks in advanced.

Damien
Site Admin
Posts: 545
Joined: Mon Dec 09, 2013 5:02 pm

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by Damien » Tue May 23, 2017 12:14 pm

The default SPI ports are defined by the ESP32 module itself (and actually the ESP IDF is doing all the low-level work here to configure the pins). If you don't provide sck/mosi/miso pins for a peripheral then the "most recent" pins are used, which is usually going to be the default pins for that peripheral.

According to the ESP IDF, the default pins for SPI(1) are: sck=Pin(6), mosi=Pin(8), miso=Pin(7). For SPI(2) it's: sck=Pin(14), mosi=Pin(13), miso=Pin(12). In MicroPython the CS pin must be handled by user code, it's not controlled by the hardware peripheral.

Capstan
Posts: 78
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by Capstan » Mon Dec 04, 2017 10:02 pm

Damien wrote:
Tue May 23, 2017 12:14 pm
According to the ESP IDF, the default pins for SPI(1) are: sck=Pin(6), mosi=Pin(8), miso=Pin(7).
Is this correct? I am looking at the WROOM-32 datasheet and also at the programming guide;
http://espressif.com/sites/default/file ... eet_en.pdf
https://esp-idf.readthedocs.io/en/v2.0/ ... aster.html

"The ESP32 has four SPI peripheral devices, called SPI0, SPI1, HSPI and VSPI. SPI0 is entirely dedicated to the flash cache the ESP32 uses to map the SPI flash device it is connected to into memory. SPI1 is connected to the same hardware lines as SPI0 and is used to write to the flash chip. HSPI and VSPI are free to use."

and...
"Host: The SPI peripheral inside the ESP32 initiating the SPI transmissions. One of SPI, HSPI or VSPI. (For now, only HSPI or VSPI are actually supported in the driver; it will support all 3 peripherals somewhere in the future.)"

This seems to imply that we should use only HSPI and VSPI for driving SPI peripherals? The datasheet looks like it is showing the VSPI pins as IO19(VSPIQ or MISO), IO23(VSPID or MOSI), and IO18(VSPICLK). The HSPI pins show as IO12(HSPIQ or MISO), IO13(HSPID or MOSI), and IO14(HSPICLK).

The micropython documentation for SPI is here;
http://docs.micropython.org/en/v1.9.3/p ... b.SPI.html

The SPI constructor mentions SPI(1) and SPI(2). The SPI(2) pins appear to correspond with VSPI. I would have thought SPI(1) pins correspond with HSPI but they don't.

Confusing, can someone clear this up?

loboris
Posts: 149
Joined: Fri Oct 02, 2015 6:19 pm

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by loboris » Mon Dec 04, 2017 11:45 pm

ESP32 SPI peripheral can be used with any GPIO via GPIO matrix (input only GPIOS can be used only for miso function).

Native SPI pins are (clk, mosi, miso, cs):
  • SPI1: 6, 8, 7, 11
  • HSPI: 14,13,12,15
  • VSPI: 18,23,19, 5
If using native pins maximum SPI clock can be set to 80 MHZ.
If using the pins routed via gpio matrix, maximum spi clock is 40 MHz in half-duplex mode and 26 MHz in full duplex mode.

Only HSPI & VSPI are supported by esp-idf driver.
Additionally, if psRAM is used with ESP32, and is set to run at 80MHz, VSPI is not available to the user, as it is used by psRAM driver.

So, in most cases (if you don't need the speed >26 MHz), you can use any pin for miso and any input/output pin for mosi, clk & cs.

Capstan
Posts: 78
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by Capstan » Tue Dec 05, 2017 12:10 am

loboris wrote:
Mon Dec 04, 2017 11:45 pm
ESP32 SPI peripheral can be used with any GPIO via GPIO matrix (input only GPIOS can be used only for miso function).

So, in most cases (if you don't need the speed >26 MHz), you can use any pin for miso and any input/output pin for mosi, clk & cs.
Good to know, thanks. But can you access selected pins with the API? According to the docs it looks like you can choose one of two 'bus' options with the SPI constructor;

The physical pins of the SPI busses are:

SPI(1) is on the X position: (NSS, SCK, MISO, MOSI) = (X5, X6, X7, X8) = (PA4, PA5, PA6, PA7)
SPI(2) is on the Y position: (NSS, SCK, MISO, MOSI) = (Y5, Y6, Y7, Y8) = (PB12, PB13, PB14, PB15)

How would you specify a different set of pins?

Also curious to know if any of the lines require pull-up resistors similar to I2C?

SpotlightKid
Posts: 298
Joined: Wed Apr 08, 2015 5:19 am

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by SpotlightKid » Tue Dec 05, 2017 1:14 am

The docs you quite refer to the Pyboard, not the ESP8266 or EPS32.

The SPI lines managed by the driver (i.e. SCK, MISO and MOSI) do not require pull-ups, they always have a defined state.

Capstan
Posts: 78
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by Capstan » Tue Dec 05, 2017 1:29 am

Ah, didn't catch that. Is the ESP32 API like the ESP8266 API? If so you can put pin designations in the constructor.

https://docs.micropython.org/en/latest/ ... achine.SPI

OutoftheBOTS_
Posts: 114
Joined: Mon Nov 20, 2017 10:18 am

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by OutoftheBOTS_ » Mon Dec 18, 2017 9:02 am

I have just changed over from ESP8266 to the ESP32. I have a Wrover board with 4mb SPI flash and 4MB SPI Ram.

I am playing with a ili9341 SPI screen. I can get it to work using any GPIO pins using software SPI and am suprised by the speed of the software SPI on the ESP32 compared to the very slow software SPI on the ESP8266

I have hooked the ili9341 to the native pins as listed above in this thread but if I try to use bus1 or bus2 it gets an error saying they r already in use (i assume the SPI RAM is using these 2 buses)

Will I be getting the full speed of 80Mhz if using these pins even though I don't specify a hardware bus ??

wallaceowen
Posts: 1
Joined: Wed Jan 03, 2018 4:00 am

Re: What are ESP32 SPI Ports for Micropython SPI(1)?

Post by wallaceowen » Wed Jan 03, 2018 4:05 am

Unlike AVR chips, specifying the pin doesn't mean you are using a 'software' spi. The ESP32 can map SPI to the pins you specify, as long as the pins you specify are capable of the job you want them to do.

Quoting Loboris: "ESP32 SPI peripheral can be used with any GPIO via GPIO matrix (input only GPIOS can be used only for miso function)."

Post Reply