Skip to content

fix: use pSPI->begin() and add skipSpiBegin option for ESP32#159

Merged
baorepo merged 1 commit into
masterfrom
fix/spi-begin-esp32-compat
May 26, 2026
Merged

fix: use pSPI->begin() and add skipSpiBegin option for ESP32#159
baorepo merged 1 commit into
masterfrom
fix/spi-begin-esp32-compat

Conversation

@baorepo
Copy link
Copy Markdown
Member

@baorepo baorepo commented May 26, 2026

Summary

  • Replace hardcoded SPI.begin() with pSPI->begin() in mcp2518fd (consistent with MCP2515)
  • Add optional _initSPI parameter (default true) to begin() across MCP_CAN, mcp2515, and mcp2518fd
  • ESP32 users can call CAN.begin(CAN_500KBPS, MCP_8MHZ, false) to skip SPI re-initialization

Why

ESP32's GPIO matrix requires users to call SPI.begin(SCK, MISO, MOSI, CS) with custom pins before using the library. The hardcoded SPI.begin() in mcp2518fd::begin() overwrites this configuration, breaking ESP32 support.

Backward compatibility

  • Default _initSPI = true — existing code works unchanged
  • Arduino Uno and other AVR platforms are unaffected (pSPI already points to &SPI)

Closes #158

…ility

ESP32 users need to call SPI.begin() with custom pin assignments before
using the library (GPIO matrix). The hardcoded SPI.begin() in
mcp2518fd::begin() overwrites this configuration.

Changes:
- Replace SPI.begin() with pSPI->begin() (consistent with MCP2515)
- Add optional _initSPI parameter (default true) to begin() across
  MCP_CAN, mcp2515, and mcp2518fd so ESP32 users can skip SPI init

Existing code is unaffected — default behavior unchanged.

Closes #158
@baorepo baorepo merged commit fc19066 into master May 26, 2026
2 checks passed
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.

SPI.begin() call in mcp2518fd::begin causes problems for other platforms

2 participants