SPI not working with MBED (was: Performance of XIAO with Sharp Memory Display)

Hey

I want to use an Adafruit Sharp Memory Display breakout board (Adafruit SHARP Memory Display Breakout - 2.7 400x240 Monochrome : ID 4694 : $44.95 : Adafruit Industries, Unique & fun DIY electronics and kits) on my XIAO.

I got it working, but it’s painfully slow when I upload the code with the “mbed-enabled” board and still slow when I do it using the “standard”-board uploader from Arduino Studio.
It runs half the framerate of what I see in the demos in the videos, I would say.

I think the XIAO should be capable enough, so is there anything that needs to be set on the XIAO to enable higher speed?

I used the pins as follows:

  • D10 for MOSI
  • D8 for SCK
  • D4 for SS/CS

I am using the provided example-code (sharpmemtest)

What could I be doing wrong?

Thanks
Raphi

ok so I debugged this the whole day now and by accident I discovered that it’s perfectly fine when using board → Seeed nrf52 boards but is slow as hell when I use board → Seed nrf52 mbed-enabled boards

which I think I have to use because I need to use ArduinoBLE which gives me a compile error on the non-BLE variant:

library ArduinoBLE claims to run on samd, megaavr, mbed, apollo3, mbed_nano, mbed_portenta, mbed_nicla, esp32 architecture(s) and may be incompatible with your current board which runs on nrf52 architecture(s).
'SerialHCI' was not declared in this scope; did you mean 'Serial'

At what speed SPI is configured?

Hi raffiniert,
1.What happens if use hardware spi instead of soft spi mode?

//Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168, 2000000);
Adafruit_SharpMem display(&SPI, D4, 144, 168, 2000000);

2.Can you increase the clock frequency which is 2MHz by default? XIAO nRF54820 can be increased up to 8MHz, but I don’t know if a Sharp allows up to what MHz.

I do not have a Sharp, so I can only check up to the compilation.

@msfujino thanks for the idea, but it’s not updating the display at all with your hardware spi - code. Instead, last image from last soft-SPI call is shown.

I tried with different clock frequencies already with no big changes.

By “slow” refresh I’m talking about ca. 3Hz (!) for a rectangle and a random number while no other code is executed but the display refresh.

Sorry: it’s running perfectly fine with your HW-SPI suggestion, when NOT using mbed. With mbed = no updates whatsoever to the screen.

it’s actually running super fast and smooth with Adafruit_SharpMem display(&SPI, D4, 400, 240, 8000000); in non-mbed-mode but doesn’t do anything when I flash the same code in mbed…

I’m really lost at this moment.

I saw this (at times, not always) when compiling:

Seeeduino/hardware/mbed/2.9.0/libraries/Spi_Flash: no headers files (.h) found in...

I ran an OLED(SSD1306) instead of a SharpMemDisplay to check the waveforms. Both clock frequencies are 8MHz, but the interval between one data transfer and the next is 20uS for mbed, while non-mbed is 6uS. The throughput is very different. The mbed’s SPI has poor performance.

so I would maybe need to rewrite my (your :slight_smile:) BLE-code to non-mbed? :-/

You may have to post to “GitHub - Seeed-Studio/ArduinoCore-mbed” and wait patiently for it to improve, or non-mbed if you are in a hurry.

but if it would only be a througput-issue, wouldn’t it still work, albeit slower?

There is another big difference in the waveforms: The mbed clock pins are set to “low power”, so the waveforms are not properly square. The non-mbed pins are set to “high power”, so they are properly square. This is just a guess, it may be that the Sharp input pins do not accept the mbed waveform.
I think there is a way to switch the pin setting to high power, but I don’t think it is easy.

and this cannot be easily changed?
I just need a working prototype, and the display I used first is completely unreadable in sunlight which is the only usecase for this application… so I thought “let’s switch to a new display, can’t be that hard”

I think there is a way to switch the pin setting to high power, but I don’t think it is easy.
If anyone has any expertise in this area、we would like some help.

1 Like

what exactly do you mean by that? Did you see this in the code or measure it with an oscilloscope?

measure it with an oscilloscope.

According to the controller datasheet, the maximum frequency of the clock is 2 MHz, the waveform will be a perfect square wave even with mbed.

so the waveform is perfect when using 2MHz, but the signal is to “weak”?

I think the input is CMOS so it shouldn’t need power.

In the case of mbed, the data transfer interval of 20uS is dominant, so even at 2MHz, the throughput will hardly decrease.

What happens if you change the setting back to software SPI and run it with pins other than D8 and D10?

hmm I think then I’m back to post 1, where it “works” but is incredibly slow?
Or did I miss something that would have changed since then?

I used the pins as follows:
D10 for MOSI
D8 for SCK
D4 for SS/CS

You are using pins other than D10 and D8 for MOSI and SCK, right?

Since OLED is working, what about the proposal to change Sharp to OLED?
I bought 128X64 for less than $10.