Using SPI Master in ESP32-C3

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Using SPI Master in ESP32-C3

Postby chegewara » Mon Apr 19, 2021 7:20 am

fasani wrote: Can you please confirm me if the ESP32C3 revision 2 can work as SPI Master?
Yes. Yesteday i tested sd card example with esp-idf and with arduino master branch.
This is capture from arduino sd card example:
Image

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: Using SPI Master in ESP32-C3

Postby fasani » Tue Apr 20, 2021 1:09 pm

Thanks PasserbyAAA and Chegewara,
I've been busy with another matters but I will try it out in the next days and get a good sample recorded with the Logic analyzer.

This is my base SPI class, just if someone spots something funny that I don't see:
https://github.com/martinberlin/cale-id ... epdspi.cpp
(Tested and working with ESP32 and ESP32S2)

Will try very soon. Like commented, epaper still does not refresh, even using the DMA channel SPI_DMA_CH_AUTO. So for sure there is something that I'm missing. Will probably test first with the ESP-IDF SPI master example (lcd)
For the record, using also latest IDF 4.4 (at the daily latest master branch)
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: Using SPI Master in ESP32-C3

Postby fasani » Sat Apr 24, 2021 6:55 am

I tried this again. Will try last time with LCD master later.

I just cannot see SPI coming out from the C3 when using latest ESP-IDF master branch.
In ESP32 with pin config (MOSI: 23 CLK: 18 CS: 5) I can see it correctly
Image


In ESP32C3 with pin config (MOSI: 7 CLK: 6 CS: 10) I see this:
Image

@cheguevara did you tried this flashing it with Espressif IDF or just with Arduino-esp32?
Can someone confirm me if it works with an SPI-IDF sketch? Can be that something is still not fully tested in IDF and it works only in Arduino ESP32?

I tried several times and I cannot get it working. No idea what is going on. Pins config seems correct (Using same pins as LCD example) I just don't see SPI coming out.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Using SPI Master in ESP32-C3

Postby chegewara » Sat Apr 24, 2021 8:08 am

Yes, i tested sd card example with both, arduino and esp-idf. In esp-idf example i did change pins to use the same as in arduino:
https://github.com/espressif/esp-idf/bl ... .c#L64-L67
https://github.com/espressif/arduino-es ... .h#L20-L23
and to change DMA channel to auto:
https://github.com/espressif/esp-idf/bl ... ain.c#L128

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: Using SPI Master in ESP32-C3

Postby fasani » Sat Apr 24, 2021 5:40 pm

I will try to use the same pins as you just to see if that is the problem. Are we using the same version of ESP32C3 ? (Mine is Revision 2)

Image

Anyways I will give it an additional try with that example or the SPI master LCD example just to see if I see SPI come out.
Last edited by fasani on Sat Apr 24, 2021 6:19 pm, edited 3 times in total.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: Using SPI Master in ESP32-C3

Postby fasani » Sat Apr 24, 2021 6:16 pm

WORKING! Your example did the trick. It seems I was just using the wrong GPIOs ( I avoided using 8 though, since it is attached to the RGB Dotstar and makes my blind.) Is there a way to use still 8 without triggering the LED?

Image

PINS used:
CONFIG_EINK_SPI_MOSI=9
CONFIG_EINK_SPI_CLK=6
CONFIG_EINK_SPI_CS=19
CONFIG_EINK_DC=18
CONFIG_EINK_RST=10
CONFIG_EINK_BUSY=7

Proof-of-concept video

One small question that I still could not solve. I got a component in my epaper library that is not compatible with the C3 (Since it uses 2 core ESP32 to drive parallel epapers)
Is there a way to tell IDF in the CMakeFile to avoid compiling this component?
I get that it should be out of the REQUIRE section and so on, but if it's on the components directory it still get's compiled (And of course won't pass since this is a different chip target)
I would really love to find a way that just tells "IF my chip target is ESP32C3" then please exclude from the build epd_driver component.

Thanks Chegevara! Really happy to get it working
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

ESP-Marius
Posts: 74
Joined: Wed Oct 23, 2019 1:49 am

Re: Using SPI Master in ESP32-C3

Postby ESP-Marius » Sun Apr 25, 2021 1:45 am

Great to hear that you got it working!

You mean exclude the whole component from being built? Then the easiest way is probably to include something like this at the top of the component you dont wanna compile's CMakeLists.txt

Code: Select all

idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "esp32c3")
        return()
endif()

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: Using SPI Master in ESP32-C3

Postby fasani » Sun Apr 25, 2021 3:30 am

Thanks Marius, awesome tip! I will use it extensively.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

nopnop2002
Posts: 112
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Using SPI Master in ESP32-C3

Postby nopnop2002 » Wed Jul 21, 2021 9:20 am

I have a problem that SPI using ESP-IDF does not work on the esp32-c3 development board.

EDIT1)

For some reason GPIO06, GPIO08, GPIO09, GPIO19 cannot be used for SPI clock pins on my board.


I looked at the ESP32-C3 datasheet, but I don't understand why.

EDIT2)
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32C3 specifications, these pins can also be used as SPI clocks.
I used a raw ESP-C3-13 to verify that these pins could be used as SPI clocks.

Who is online

Users browsing this forum: cdollar and 134 guests