Hi,
Environment:
board ESP32-C3-DevKitC-02
ESP-IDF V4.3
chip revision 3
Issue
I have an issue with SPI master.
ret = spi_bus_initialize(SPI2_HOST, &buscfg, DMA_CHAN); this is OK
but
ret = spi_bus_initialize(SPI3_HOST, &buscfg, DMA_CHAN); this is not OK
During execution, it fails with the error message:
spi_bus_initialize(627): invalid host_id
But SPI3_HOST should be recognized as illustrated hereunder.
in spi_types.h
SPI_EV_BUF_TXtypedef enum {
//SPI1 can be used as GPSPI only on ESP32
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
} spi_host_device_t;
I did some search and found that in spi_common.c line 102
static inline bool is_valid_host(spi_host_device_t host)
{
#if (SOC_SPI_PERIPH_NUM == 2)
return host >= SPI1_HOST && host <= SPI2_HOST;
#elif (SOC_SPI_PERIPH_NUM == 3)
return host >= SPI1_HOST && host <= SPI3_HOST;
#endif
}
looking at socs_caps.h line 175
#define SOC_SPI_PERIPH_NUM 2
So why it is 2 instead or 3, ESP32-C3 has 3 SPI interface and SPI3_HOST is for general purpose ???
ESP32-C3 SPI3_HOST not recognized
-
- Posts: 6
- Joined: Fri Aug 13, 2021 8:42 am
ESP32-C3 SPI3_HOST not recognized
Last edited by bernardbru on Fri Aug 13, 2021 12:25 pm, edited 1 time in total.
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32-C3 SPI3_HOST not recognized
The ESP32C3 only has SPI0 (unusable by software as it is controlled by the flash cache) SPI1 (which is kinda hard to use as it's also connected to the flash) and SPI2; the hardware does not contain SPI3.
-
- Posts: 6
- Joined: Fri Aug 13, 2021 8:42 am
Re: ESP32-C3 SPI3_HOST not recognized
You are correct there are only 3 SPI interface but SPI3_HOST exist .
or to simplify SPI0, SPI1, SP2
What I see is using the value 2, it doesn't work : error message "invalid host_id"
So on my side, I can't access the third SPI interface.
Could you ?
spi_types.h
SPI_EV_BUF_TXtypedef enum {
//SPI1 can be used as GPSPI only on ESP32
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
} spi_host_device_t;
or to simplify SPI0, SPI1, SP2
What I see is using the value 2, it doesn't work : error message "invalid host_id"
So on my side, I can't access the third SPI interface.
Could you ?
spi_types.h
SPI_EV_BUF_TXtypedef enum {
//SPI1 can be used as GPSPI only on ESP32
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
} spi_host_device_t;
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32-C3 SPI3_HOST not recognized
SPI3 (or SPI3_HOST) does *not* exist in the -C3. From the datasheet: "ESP32-C3 family features three SPI interfaces (SPI0, SPI1, and SPI2). SPI0 and SPI1 can only be configured to operate in SPI memory mode, while SPI2 can be configured to operate in both SPI memory and general-purpose SPI modes." The define is in there because other ESP32s have a fourth SPI interface called SPI3 (note we start counting from SPI0, so SPI3 is the fourth SPI interface) but the -C3 does not. The header file you see does not mention SPI0 (and does not have an enum value for it) as it's special in all ESP32 chips and never usable by software, so there's no need to have an identifier for it.
-
- Posts: 6
- Joined: Fri Aug 13, 2021 8:42 am
Re: ESP32-C3 SPI3_HOST not recognized
Thank you ESP_Sprite, using SPI1 it works
Who is online
Users browsing this forum: No registered users and 25 guests