Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

ESP32 feather + DotStar strip using hardware SPI
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP32 feather + DotStar strip using hardware SPI

by solaria123 on Sun Jan 16, 2022 4:24 pm

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 | TOGGLE FULL SIZE
   #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 | TOGGLE FULL SIZE
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?

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

Re: ESP32 feather + DotStar strip using hardware SPI

by solaria123 on Wed Jan 19, 2022 10:20 pm

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 | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
    #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 | TOGGLE FULL SIZE
    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...

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

Re: ESP32 feather + DotStar strip using hardware SPI

by adafruit2 on Thu Jan 20, 2022 1:37 pm

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

adafruit2
Site Admin
 
Posts: 20869
Joined: Fri Mar 11, 2005 7:36 pm

Re: ESP32 feather + DotStar strip using hardware SPI

by solaria123 on Thu Jan 20, 2022 11:33 pm

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

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

Re: ESP32 feather + DotStar strip using hardware SPI

by adafruit_support_carter on Fri Jan 28, 2022 1:07 pm

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

adafruit_support_carter
 
Posts: 23548
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.