Skip to content

Fix SPI bus detach issue on ESP32-C3 with Arduino 3.x - #176

Open
hallard wants to merge 1 commit into
LSatan:masterfrom
hallard:fix-spi-esp32c3
Open

Fix SPI bus detach issue on ESP32-C3 with Arduino 3.x#176
hallard wants to merge 1 commit into
LSatan:masterfrom
hallard:fix-spi-esp32c3

Conversation

@hallard

@hallard hallard commented Feb 14, 2026

Copy link
Copy Markdown

Summary

  • Fix SPI bus initialization/teardown that breaks CC1101 on ESP32-C3 with Arduino 3.x (IDF 5.x)
  • SPI.end() now fully detaches the SPI bus and releases GPIO pins on newer ESP32 Arduino cores
  • Since SpiStart()/SpiEnd() wrap every single SPI transaction, this caused the bus to be repeatedly torn down and rebuilt, hanging the firmware

Changes

  • SpiStart(): Only call SPI.begin() and pinMode() once (first use), skip on subsequent calls
  • SpiEnd(): Remove SPI.end(), keep only SPI.endTransaction()

Testing

  • Tested on ESP32-C3 with CC1101 module using custom SPI pins
  • Arduino ESP32 core 3.3.3 / IDF v5.5.1
  • Compatible with ESP32, ESP32-S3, and ESP8266 (no behavior change on those platforms)

🤖 Generated with Claude Code

On ESP32-C3 with Arduino 3.x (IDF 5.x), SPI.end() fully detaches the
SPI bus and releases GPIO pins. Since SpiStart()/SpiEnd() are called
around every single SPI transaction, this causes the bus to be
repeatedly torn down and rebuilt, which breaks GPIO pin assignments
and hangs the firmware.

Fix by:
- Only calling SPI.begin() once (on first use) instead of every transaction
- Removing SPI.end() from SpiEnd(), keeping only SPI.endTransaction()

This fixes CC1101 operation on ESP32-C3 boards while remaining
compatible with ESP32, ESP32-S3, and ESP8266.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1technophile added a commit to 1technophile/OpenMQTTGateway that referenced this pull request Aug 9, 2026
…fore probe

On the platform we ship (pioarduino 55.03.39 / arduino-esp32 3.3.9) the pinned
SmartRC-CC1101-Driver-Lib v2.5.7 does not work with the CC1101 at all. Core 3.x's
peripheral manager owns SCK/MISO/MOSI once SPI.begin() has run, so the driver's
digitalWrite() calls on those pins become silent no-ops, and it starts and stops
the SPI bus around every single register access (LSatan/SmartRC-CC1101-Driver-Lib#176).

Bench result on an ESP32 DevKit + CC1101 running esp32dev-pilight-cc1101: setup
hangs in the driver's unbounded `while(digitalRead(MISO_PIN));` before any C1101
log line is emitted, and TG1WDT reboots the board in a loop. The same build on
espressif32@6.8.1 (core 2.0.17) initialises normally, so this is the core, not
the wiring. Every ZradioCC1101 ESP32 environment is affected: Pilight, RF, RF2
and Somfy. The RTL_433 CC1101 path goes through RadioLib and is unaffected.

V3.0.x re-engineered the SPI core for ESP32: gpio_get_level() with a timeout
instead of the unbounded digitalRead() wait, SPI.begin() once instead of per
transaction, and no digitalWrite() on peripheral-owned pins. It also moved
SPI.begin() out of getCC1101() and into Init(), so the connection probe has to
run after Init() rather than before it — reported in #2348.

Both changes are needed together: the reorder alone does not help on core 3.x,
and V3 cannot work without it.

Verified on the bench, core 3.3.9, esp32dev-pilight-cc1101:
  N: C1101 SPI connection OK on attempt 1
  N: C1101 tuned RX to 433.92 MHz
plus a live round trip — an arctech_switch frame published to MQTTtoPilight was
transmitted and decoded back by the board's own receiver on PilighttoMQTT.

Note for review: this bumps the pin for the ESP8266 CC1101 environments too.
They are not affected by the core 3.x breakage and V3 is untested there, so the
pin may be worth splitting per environment before this lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1technophile added a commit to 1technophile/OpenMQTTGateway that referenced this pull request Aug 15, 2026
…fore probe (#2353)

On the platform we ship (pioarduino 55.03.39 / arduino-esp32 3.3.9) the pinned
SmartRC-CC1101-Driver-Lib v2.5.7 does not work with the CC1101 at all. Core 3.x's
peripheral manager owns SCK/MISO/MOSI once SPI.begin() has run, so the driver's
digitalWrite() calls on those pins become silent no-ops, and it starts and stops
the SPI bus around every single register access (LSatan/SmartRC-CC1101-Driver-Lib#176).

Bench result on an ESP32 DevKit + CC1101 running esp32dev-pilight-cc1101: setup
hangs in the driver's unbounded `while(digitalRead(MISO_PIN));` before any C1101
log line is emitted, and TG1WDT reboots the board in a loop. The same build on
espressif32@6.8.1 (core 2.0.17) initialises normally, so this is the core, not
the wiring. Every ZradioCC1101 ESP32 environment is affected: Pilight, RF, RF2
and Somfy. The RTL_433 CC1101 path goes through RadioLib and is unaffected.

V3.0.x re-engineered the SPI core for ESP32: gpio_get_level() with a timeout
instead of the unbounded digitalRead() wait, SPI.begin() once instead of per
transaction, and no digitalWrite() on peripheral-owned pins. It also moved
SPI.begin() out of getCC1101() and into Init(), so the connection probe has to
run after Init() rather than before it — reported in #2348.

Both changes are needed together: the reorder alone does not help on core 3.x,
and V3 cannot work without it.

Verified on the bench, core 3.3.9, esp32dev-pilight-cc1101:
  N: C1101 SPI connection OK on attempt 1
  N: C1101 tuned RX to 433.92 MHz
plus a live round trip — an arctech_switch frame published to MQTTtoPilight was
transmitted and decoded back by the board's own receiver on PilighttoMQTT.

Note for review: this bumps the pin for the ESP8266 CC1101 environments too.
They are not affected by the core 3.x breakage and V3 is untested there, so the
pin may be worth splitting per environment before this lands.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant