Page 1 of 1

Dual SPI on ESP32-WROOM-32E

Posted: Tue May 28, 2024 7:05 am
by RonKremborg
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:

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();
The stepper controller has variable length commands (in count):

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();
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

Re: Dual SPI on ESP32-WROOM-32E

Posted: Tue May 28, 2024 8:25 am
by tanmanh0707
Since CS, MOSI and SCLK are working on your scope, I doubt the issue is from your stepper. I suggest removing SD card out and check only stepper if it works firstly.

Re: Dual SPI on ESP32-WROOM-32E

Posted: Tue May 28, 2024 1:28 pm
by RonKremborg
Good idea. I'll try that tomorrow.
Regards, Ron