ESP32 feather + DotStar strip using hardware SPI

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
solaria123
 
Posts: 13
Joined: Mon Jan 09, 2017 4:07 pm

ESP32 feather + DotStar strip using hardware SPI

Post by solaria123 »

While connecting a DotStar strip to an ESP32 Feather, I noticed this comment in strandtest.ino:
// Hardware SPI is a little faster, but must be wired to specific pins
// (Arduino Uno = pin 11 for data, 13 for clock, other boards are different).
//Adafruit_DotStar strip(NUMPIXELS, DOTSTAR_BGR);
Sounds good; faster is better. Which pins? In pins_adruino.h for the feather_esp32:
static const uint8_t SS = 33;
static const uint8_t MOSI = 18;
static const uint8_t MISO = 19;
static const uint8_t SCK = 5;
...matches the silkscreen on the Feather.

I connected the DotStar strip to pins 5 (SCK), 18 (MO) and modified strandtest.ino:

Code: Select all

	#define DATAPIN    18
	#define CLOCKPIN   5
	Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BGR);
The software SPI works fine, but when I modify it for hardware SPI:

Code: Select all

Adafruit_DotStar strip(NUMPIXELS, DOTSTAR_BGR);
...it doesn't work at all. In fact, probing with an oscilloscope, I don't see anything that looks like clock/data on any pin.

I guess I'm missing something? How do you get hardware SPI to work?

User avatar
solaria123
 
Posts: 13
Joined: Mon Jan 09, 2017 4:07 pm

Re: ESP32 feather + DotStar strip using hardware SPI

Post by solaria123 »

Well, I found the problem. When the Adafruit_DotStar.cpp library initializes the hardware SPI, it sets the clock speed with this:

Code: Select all

SPI.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due
Seems reasonable, but that command on the ESP32 instantly kills the SPI. Changing it to match the code used for the ESP8266 fixes it:

Code: Select all

    #if defined(ESP8266) || defined(ESP32)
        SPI.setFrequency(8000000L);
Unfortunately, even though it can now clock the bits out really fast, it has relatively large gaps between the bytes, so the data rate is actually slower than the software SPI rate. For each byte written, the SPI driver waits for command completion:

Code: Select all

    spi->dev->cmd.usr = 1;
    while(spi->dev->cmd.usr);
...which can take about 10us at 500K clock. Need to change the DotStar library to use SPI.writeBytes() instead, so that it writes out the entire pixel buffer at once, instead of a byte-at-a-time.

Meanwhile: I modified the DotStar software SPI code to use GPIO.out instead of digitalWrite(), and got the clock rate up to about 6MHz...

User avatar
adafruit2
 
Posts: 22149
Joined: Fri Mar 11, 2005 7:36 pm

Re: ESP32 feather + DotStar strip using hardware SPI

Post by adafruit2 »

huh - yep sounds like a bug! wanna submit a PR to github? :)
for the non-blocking version, you could add two functions - a nonblocking write an a 'data complete' checker

User avatar
solaria123
 
Posts: 13
Joined: Mon Jan 09, 2017 4:07 pm

Re: ESP32 feather + DotStar strip using hardware SPI

Post by solaria123 »

I just checked: PR#22: "add ESP32: set hardware SPI frequency on ESP32, same as ESP8266." has been open since July 2017. Waiting for someone with write access I guess?

Optimizing the SPI to write the entire pixel buffer with SPI.writebytes(), instead of writing individual bytes with SPI.transfer(), works really well. At 15Mhz clock, can update a 288 LED strip in 780 microseconds

User avatar
adafruit_support_carter
 
Posts: 29189
Joined: Tue Nov 29, 2016 2:45 pm

Re: ESP32 feather + DotStar strip using hardware SPI

Post by adafruit_support_carter »

Some of this may have been fixed by the BusIO conversion update. Please try the 1.2.0 release:
https://github.com/adafruit/Adafruit_DotStar/releases

The data is still being sent out using transfer, so there may still be some optimization that could be done. If the latest release is still showing the "large gaps", please consider opening a new issue:
https://github.com/adafruit/Adafruit_DotStar/issues

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”