I tried to create an alternate SPI bus for the ESP32-POE. The default SPI pins were not working while connected via POE. For this I used the multiple SPI bus example from the ESP32 Arduino libraries. I'm trying to run the bus at a modest 1MHz. I'm also running the Ethernet ETH.h library.
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino
Some sample code:
#include <SPI.h>
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12
#include <ETH.h>
#define HSPI_SCLK 33
#define HSPI_MISO 34
#define HSPI_MOSI 35
#define HSPI_SS 36
SPIClass * hspi = NULL;
void setup() {
Serial.begin(115200);
WiFi.onEvent(WiFiEvent);
ETH.begin();
// init SPI
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
}
The error message:
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
ETH Started
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d25bb PS : 0x00060e30 A0 : 0x800d08d6 A1 : 0x3ffb1ed0
A2 : 0x00000000 A3 : 0x000f4240 A4 : 0x00000001 A5 : 0x3ffc2b64
A6 : 0xffffffff A7 : 0x00000000 A8 : 0xfffffffb A9 : 0x3ffb1ec0
A10 : 0x00000002 A11 : 0x0000005a A12 : 0x3ffc2c02 A13 : 0x00000002
A14 : 0x00000001 A15 : 0x3ffbdc74 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x400d25bb:0x3ffb1ed0 0x400d08d3:0x3ffb1f00 0x400d0a93:0x3ffb1f30 0x400d0b8c:0x3ffb1f50 0x400d15f6:0x3ffb1f70 0x400d55ba:0x3ffb1fb0 0x4008a512:0x3ffb1fd0
Rebooting...
edit:
I was able to find the problem. The libraries which relied on the SPI instance were using the static SPI instance rather than the SPIclass instance so hspi->begin(...) is not enough. You must also alter the library to accept the class instance. In my case: mfrc522.attachSPI(hspi); // must be called first. I hope this helps someone else!