Very slow SPI on ESP32?

Posted on
  • I'm playing around with one of the TTGO boards. It has an ILI9341 screen. But it looks like SPI is running at an extremely low rate. It takes several seconds just to clear the screen.

    SPI1.setup({sck:D18, miso:D12, mosi:D23, baud: 1000000});
    var g = require("ILI9341").connect(SPI1, D26, D27, D5, function() {
      g.clear();
      g.drawString("Hello",0,0);
      g.setFontVector(20);
      g.setColor(0,0.5,1);
      g.drawString("Espruino",0,10);
    });
    

    I found an old thread that mentioned ESP32 defaulting to 100kbs and ignoring the baud setting. Is that still true? Any way around it? Thanks.

  • I believe the ESP8266/ESP32 hardware SPI code isn't that speedy in general. Espruino expects to be able to queue a byte to send, then go away and work out the next byte while the first is sending. The ESPxx API doesn't let it do that so it has to send a byte, pause while it works out the next one, and so on.

    You could try software SPI? Not sure if that'll be faster, but it might be as it runs as fast as it can - especially if you don't specify a MISO pin, because you don't actually care about receiving data.

  • Thanks Gordon, I'll give that a try later.

  • About twice as fast in software. Bummer about the hardware speed.

    var spi = new SPI();
    spi.setup({sck:D18, mosi:D23, baud: 4000000});
    var g = require("ILI9341").connect(spi, D26, D27, D5, function() {
      g.clear();
      g.drawString("Hello",0,0);
      g.setFontVector(20);
      g.setColor(0,0.5,1);
      g.drawString("Espruino",0,10);
    });
    
  • The esp32 esp-idf allows a string to be sent - can you think of a way of keeping the existing code and also using the output as a string ? I suppose it could be done with the #ifdef but wondering if there is a cleaner way?

  • There's no easy way - in some cases the SPI could be sent a buffer, but for what the ILI9341 driver is doing here (sending a block of the same color) it's not going to work. Neither would it work for a bunch of other stuff.

    Basically we'd end up doing a massive hack and then maybe the ILI9341 would be twice as fast - but still too slow to be useful.

    Personally I'd like to sort out SPI properly so that it could work with buffers and DMA. That'd massively improve performance on all platforms.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Very slow SPI on ESP32?

Posted by Avatar for ConorONeill @ConorONeill

Actions