ESP32-S3 SPI: dynamically remap SCLK pin between transactions

Deleted
Posts: 2
Joined: Fri Oct 17, 2025 5:44 pm

ESP32-S3 SPI: dynamically remap SCLK pin between transactions

Postby Deleted » Fri Oct 17, 2025 6:05 pm

Hi everyone,

I’m working on an ESP32-S3 project where I need to communicate with multiple ADCs through isolation.
Each ADC uses a 3-wire SPI interface (no CS), and I’d like to select each ADC by switching which GPIO outputs the SPI clock (SCLK) signal.
The goal is to reassign the SCLK pin between polling each ADC instead of using separate SPI peripherals or additional isolator chips.

Why I want to do this

I have very limited PCB space, and there isn’t enough room between the ICs to route extra CS lines or add more vias and traces.
If I used a dedicated chip-select for each ADC, it would require additional SOIC-8 digital isolators, which I’m trying to avoid to keep the board compact.

This approach would allow me to:

Use just two SOIC-8 digital isolators plus one additional isolated GPIO that I already need.

Enable the clock only for the active ADC, keeping the others idle — which may also help reduce emitted noise from the shared SPI lines. (and current consumption)

Keep the overall design smaller and simpler, while still polling each ADC independently.

What I tried

I attempted to use gpio_matrix_out() to remap the SPI clock signal from one GPIO to another between transactions.
My sequence looks like this:

Code: Select all

// 1. Finish one SPI transaction
// 2. Disable the current SCLK pin
gpio_matrix_out(current_io, 0x100, false, false);

// 3. Enable the next GPIO for SCLK
gpio_matrix_out(new_io, spi_periph_signal[host_].spiclk_out, false, false);
buscfg_.sclk_io_num = sclk_io_num;

// 4. Start the next transaction
However, I noticed the following behavior:

If I disable the currently active SCLK pin first, ALL pins doesn’t output any clock after remapping.

If I don’t disable the current pin (the one configured during initialization), then both GPIOs toggle simultaneously with the clock signal.

It seems that once I disconnect the current SCLK output, the SPI peripheral stops driving the internal clock signal, or perhaps it requires some kind of restart — which I’d like to avoid since reinitializing the SPI driver every time would add latency.

My question

👉 Is it possible to dynamically reassign the SPI SCLK pin (on ESP32-S3) between transactions without reinitializing the SPI driver each time?

If yes:

What’s the correct way to safely switch the clock pin using the GPIO matrix?

Do I need to re-enable the SPI peripheral or clear/restart something after remapping?

Any low-level insights, register-level details, or working code examples would be very helpful.

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 SPI: dynamically remap SCLK pin between transactions

Postby Sprite » Sat Oct 18, 2025 12:42 am

If you're using the ESP-IDF SPI driver, you may want to look at SPI_DEVICE_CLK_AS_CS. (If not, it's actually hardware functionality, you can also find a corresponding bit in the register descriptions.)

Deleted
Posts: 2
Joined: Fri Oct 17, 2025 5:44 pm

Re: ESP32-S3 SPI: dynamically remap SCLK pin between transactions

Postby Deleted » Sat Oct 18, 2025 9:47 am

If you're using the ESP-IDF SPI driver, you may want to look at SPI_DEVICE_CLK_AS_CS. (If not, it's actually hardware functionality, you can also find a corresponding bit in the register descriptions.)
Thanks for the reply!
I checked, and it looks like there’s also a #if SOC_SPI_AS_CS_SUPPORTED define — but it seems this flag isn’t set for the ESP32-S3 MCU, only for the ESP32.
Or maybe I’m mistaken?

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 SPI: dynamically remap SCLK pin between transactions

Postby Sprite » Sun Oct 19, 2025 2:13 pm

Hm, you're right - I didn't realize that dropped out with the -S3. From what I can see, your original approach of messing with the GPIO matrix should work... can you try to see if you can maybe initially initialize the SPI master driver on a dummy GPIO, then use the matrix to enable/disable the real GPIOs? If that works, there's something still depending on the bus info in the SPI driver software, and that may not be updated correctly.

Who is online

Users browsing this forum: Google [Bot], Qwantbot, RandomInternetGuy, Semrush [Bot] and 3 guests