Dual SPI on ESP32-WROOM-32E
Posted: Tue May 28, 2024 7:05 am
In a PlatformIO and Arduino environment, I have 2 SPI devices: An SDCard and a stepper motor controller. The former is SPI_MODE0 and the latter SPI_MODE3. The board I am using (Sparkfun ESP32 RedBoard) does not bring GPIO12 to a connector, so I need to put both devices on VSPI. Here is how I have set it up. The SDCARD code segment is:
The stepper controller has variable length commands (in count):
However, while the SDCard code works, for the stepper although the CS, MOSI and SCLK lines seem to be working as seen on my scope, no data gets transferred from the stepper controller. I would welcome any advice on what I am doing wrong.
Ron
Code: Select all
vSPI.beginTransaction(SPISettings(Motor.GetSpiClk(), MSBFIRST, SPI_MODE0));
SD.begin(SDCARD_CS, vSPI);
Card.AppendFile(TheFile, (char*)dataLine);
SD.end();
vSPI.endTransaction();
Code: Select all
vSPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE3));
digitalWrite(STEPPER_CS, LOW); // enable the powerstep chip select
i = 0; // clear output buffer index
while (count-- > 0)
{
retVal = vSPI.transfer(*ptr); // transfer in/out
}
digitalWrite(STEPPER_CS, HIGH); // disable the chip select
vSPI.endTransaction();
Ron