Hardware SPI Pins

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Hardware SPI Pins

Post by rdagger » Sat Nov 11, 2017 7:53 am

On the ESP32, what are the native GPIO pins for hardware SPI on bus ID 1 and 2?

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: Hardware SPI Pins

Post by rdagger » Sat Nov 11, 2017 5:40 pm

It looks like there are 2 available SPI buses on the ESP32: HSPI=1 and VSPI = 2.
HSPI is MOSI=GPIO13, MISO=GPIO12 and SCK=GPIO14
VSPI is MOSI=GPIO23, MISO=GPIO19 and SCK=GPIO18

However, the machine SPI class does seem to work unless I pass the pin values. For example.

Code: Select all

spi = SPI(1, baudrate=12500000) 
doesn't work with an SSD1351 connected to MOSI=GPIO13 and SCK=GPIO14

Code: Select all

spi = SPI(2, baudrate=12500000) 
also doesn't work with MOSI=GPIO23 and SCK=GPIO18

However, it does work if I specify the GPIO pins as arguments:

Code: Select all

spi = SPI(2, baudrate=12500000, sck=Pin(18), mosi=Pin(23))
The problem is that I don't think this is giving me true hardware performance because I should be getting around 20MHz but the maximum baud rate I can use is 12.5MHz.

MrSurly
Posts: 7
Joined: Wed Apr 19, 2017 6:08 pm

Re: Hardware SPI Pins

Post by MrSurly » Sun Nov 12, 2017 2:58 am

Hi,

You can use HW SPI with just about any of the pins, but when you use the "native" pins for a particular HW SPI, you should be able to achieve much higher baud rates.

Yes, you must pass the actual Pin() objects.

For HSPI (id = 1), the pins are:

CLK: 14
MOSI: 13
MISO: 12

For VSPI (id = 2):
CLK: 18,
MOSI: 23,
MISO: 19,


Also, are you using a new enough MicroPython that you're not seeing this issue: https://github.com/micropython/micropyt ... ssues/189

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: Hardware SPI Pins

Post by rdagger » Sun Nov 12, 2017 3:19 am

I'm using today's build. Thanks.

Post Reply