Issues with SPI on XIAO esp32s3

Hi,

I made an Arduino program for the ADS1262 ADC with XIAO sense nrf52840. It seems to work as expected. My ADC seems to read the voltage given at its input accurately. I tested this program with Arduino UNO and everything seems to work well there as well.
However, when I try loading the same program to the XIAO ESP32S3. My ADC reads always 0 irrespective of the input voltage. I wanted to switch to XIAO ESP32S3 because of its fast processor. I thought since both the XIAO ESP32S3 and XIAO sense nrf52840 have the same pinout I would be able to make the switch work. However, it seems to be not the case…

It would be great if someone can help me out with this issue.

Thank you!

The following sketch may be helpful.

File/Examples/Examples for XIAO_ESP32S3/SPI/SPI_Multiple_BUses

Thank you for the tip. I had a follow-up question.
I noticed that the program was using two SPIs. Which is the one that correlates with the SPI pins that is accessible in the board?

For example, SD initialization using SPI is as follows.

#define sd_sck   D8
#define sd_miso  D9
#define sd_mosi  D10
#define sd_ss    D2

void setup() {
  SPI.begin(sd_sck, sd_miso, sd_mosi, sd_ss);
  SPI.setDataMode(SPI_MODE3);
  SPI.setHwCs(true);

  if(!SD.begin(sd_ss, SPI, 40000000, "/sd")){
    while (1);
  }

keep in mind a XIAO ESP32S3 is not the same as an Arduino Uno… different everything… different communication hardware… different voltages … different everything… its not going to be plug and play swap… FYI

One thing to check is the SPI pin configuration—even though the XIAO ESP32S3 and the XIAO Sense nRF52840 have similar pinouts, the ESP32S3 might handle SPI differently, especially with its higher processing speed. Double-check that the pins for MISO, MOSI, SCK, and CS are correctly assigned for the ESP32S3 in your code. Another potential cause could be voltage level compatibility—the ESP32S3 uses 3.3V logic, while the ADS1262 might expect 5V signals, so you might need a level shifter. You could also try lowering the SPI clock speed to see if that helps with communication stability. Hope that helps narrow it down! Let us know if you find the solution!

Hi there,
So, I have a demo on here “grove Expansion Flash” it is an SPI flash you can add to the bottom of the board, Look at that code demo, has both NRF and ESP versions to clearly see the difference. The trick with the Nordic Nrf52x devices is the SPI interfaces as NRF_SPIM0, NRF_SPIM1, NRF_SPIM2, NRF_SPIM3 for which buss. device mode or method.
ESP32-S3 has the following SPI interfaces:
• SPI0 used by ESP32-S3’s cache and Crypto DMA (EDMA) to access in-package or off-package
flash/PSRAM
• SPI1 used by the CPU to access in-package or off-package flash/PSRAM
• SPI2 is a general purpose SPI controller with its own DMA channel
• SPI3 is a general purpose SPI controller with access to a DMA channel shared between several peripherals
Between the Pin “XLS” sheets for both devices you can look and see which is connected to what.
HTH
GL :slight_smile: PJ :v:

I alway find it (the SPI) or the (CS, SS) are not what you think.So I always run a sanity check code to print out what the MCU thinks it is, you see that in the demo as well.

 Serial.println("--------------");
 Serial.println(SS_SPI0);
 Serial.println(MOSI); // master out, slave in
 Serial.println(MISO); // master in, slave out
 Serial.println(SCK);  // clock
 Serial.println("--------------");

and here is a snip from the Flash Test Example for a C3 notice the defines. :v:


//static const int spiClk = 40000; // 1 MHz
//#define ALTERNATE_PINS
#ifdef ALTERNATE_PINS
  #define VSPI_MISO   9
  #define VSPI_MOSI   10
  #define VSPI_SCLK   8
  #define VSPI_SS     3

  #define HSPI_MISO   26
  #define HSPI_MOSI   27
  #define HSPI_SCLK   25
  #define HSPI_SS     32
#else
  #define VSPI_MISO   MISO
  #define VSPI_MOSI   MOSI
  #define VSPI_SCLK   SCK
  #define VSPI_SS     SS

  #define HSPI_MISO   9
  #define HSPI_MOSI   10
  #define HSPI_SCLK   8
  #define HSPI_SS     3
#endif
//uninitalised pointers to SPI objects
SPIClass * fspi = NULL;
SPIClass * hspi = NULL;
//spi = SPIClass(FSPI);  // working
SPIClass VSPI (SPI);  // Change here to specify the SPI port (HSPI, VSPI, or SPI)
Adafruit_FlashTransport_SPI EflashTransport(SS, &SPI);  // Flash Type
Adafruit_SPIFlash Eflash(&EflashTransport); 
#define SS 3


void setup() {
  Serial.begin(9600);
  while (!Serial) delay(2100);
    Serial.println();
  Serial.println(" Program " __FILE__ " compiled on " __DATE__ " at " __TIME__ );
  
  fspi = new SPIClass(FSPI);
  hspi = new SPIClass(HSPI);
 
  pinMode(SS, OUTPUT); // CS for flash
  digitalWrite(SS, HIGH); // <-- Set CS pin HIGH to deselect

  pinMode(fspi->pinSS(), OUTPUT); //VSPI SS
  pinMode(hspi->pinSS(), OUTPUT); //HSPI SS
  digitalWrite(SS, HIGH); // <-- Set CS pin HIGH to deselect
  Serial.println("--------------");
  Serial.println(SS);
  Serial.println(MOSI); // master out, slave in
  Serial.println(MISO); // master in, slave out
  Serial.println(SCK);  // clock
  Serial.println("--------------");

fspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
delay(250);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS

  Serial.println(F("Expansion Flash ID"));
   // Initialize ESP32c3 onboard flash library and check its chip ID.
 

:+1:

2 Likes