Communicating between Seeed Studio XIAO ESP32S3 and ADS8341 (SPI)

I've been trying to get the ADS8341 to communicate with the XIAO ESP32S3 but can't get information from it. I'm using code I've found that's said to work but am only getting a constant 0 output. I'm new to using SPI so any help would be appreciated, here's the code for reference

#include <SPI.h>
//based off GPIO??
// #define CS 1
// #define MOSI 9
// #define MISO 8
// #define SPICLOCK 7=

#define SELPIN 1  // Chip select pin (any digital pin)

void setup() {
  Serial.begin(9600);

  //Set pin modes
  pinMode(SELPIN, OUTPUT);
  digitalWrite(SELPPIN, HIGH);  //disable device at start

  //initialize SPI library
  SPI.begin();
  //Configure SPI settings: Speed(data sheet), MSBFIRST, SPI_MODE0
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));
}
int read_adc(int channel) {
  int adcvalue = 0;
  byte commandbits;

  //make command byte based on desired channel
  switch (channel) {
    case 0:
      commandbits = 0x97;  //Channel 0
      break;
    case 1:
      commandbits = 0x00;  //need to fill later for Channel 1
      break;
    default:
      commandbits = 0x97;
      break;
  }
  digitalWrite(SELPIN, LOW);            //select ADC
  SPI.transfer(commandbits);            //send the command byte and recive the first responce simutaneously
  byte response1 = SPI.transfer(0x00);  //send dummy byte
  byte responce2 = SPI.transfer(0x00);  //dummy byte

  digitalWrite(SELPIN, HIGH);  //deselect ADC

  adcvalue = (response1 << 8) | response2;

  return adcvalue;
}

void loop() {
  int value0 = read_adc(0);
  // int value1=read_adc(1); //channel 1

  Serial.print("Channel 0 value");
  Serial.println(value0);
  // Serial.print("Channel 1 value");
  // Serial.println(value1);
  Serial.println(" ");

  delay(500);
}

I recall when first using the XIAO that the pin numbers were unusual. I don;t recall what I ended up with but I used a simple light a led sketch to determine what a physical poin was called. As I recall, they are out by one.

I did that to confirm the pinouts, it is was correct in that regard as well as using a serial.print of the MOSI, MISO, and SCK without defining the pins in a separate sketch

In the title you refer to ADS8341

Which one is it?

sorry for the confusion its the ADS8341

@bremorris

The device has a SHUTDOWN (SHDN) pin.
How is it connected? or not?

https://www.ti.com/lit/ds/symlink/ads8341.pdf

The code you posted won't compile as it has typos in it.
The SPI transaction is not complete.

Fixed the above and added channel 1,2 and 3 too
Please give it a try (as I do not have the hardware I can't)

#include <SPI.h>

//based off GPIO??
// #define CS 1
// #define MOSI 9
// #define MISO 8
// #define SPICLOCK 7=

#define SELPIN 1   //  Chip select pin (any digital pin)


uint16_t read_adc(int channel)
{
  uint8_t commandbits = 0x97;  //  default, channel 0

  //  make command byte based on desired channel
  switch (channel)
  {
    case 0:
      commandbits = 0x97;  //  Start bit, Channel 0 + no shutdown between conversions.
      break;
    case 1:
      commandbits = 0xD7;
      break;
    case 2:
      commandbits = 0xA7;
      break;
    case 3:
      commandbits = 0xE7;
      break;
    default:
      commandbits = 0x97;  //  channel 0
      break;
  }

  //  Configure SPI settings: Speed(data sheet), MSBFIRST, SPI_MODE0
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

  digitalWrite(SELPIN, LOW);               //  select ADS8341
  SPI.transfer(commandbits);               //  send the command byte and receive the first response simultaneously
  uint8_t response1 = SPI.transfer(0x00);  //  send dummy byte, receive HIGH byte
  uint8_t response2 = SPI.transfer(0x00);  //  send dummy byte, receive LOW byte
  digitalWrite(SELPIN, HIGH);              //  deselect ADC

  SPI.endTransaction();

  return response1 * 256 + response2;
}


void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(__FILE__);
  Serial.println();

  //  Set pin modes
  pinMode(SELPIN, OUTPUT);
  //  unselect device at start
  digitalWrite(SELPIN, HIGH);

  //  initialize SPI library
  SPI.begin();
}


void loop()
{
  for (int channel = 0; channel < 4; channel++)
  {
    uint16_t value = read_adc(channel);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(": ");
    Serial.println(value);
    Serial.println();
    delay(500);
  }

  delay(1000);
}

thanks for the response the SHDN pin is connected to 3.3VCC. i've tried the code and had no luck, im still getting a constant readout of 0.

please post 20 lines of output

heres the output

Channel 0: 0

Channel 1: 0

Channel 2: 0

Channel 3: 0

Channel 0: 0

Channel 1: 0

Channel 2: 0

Channel 3: 0

Channel 0: 0

Channel 1: 0

Channel 2: 0

Channel 3: 0

Channel 0: 0

Channel 1: 0

Channel 2: 0

Channel 3: 0

Have you read the data sheet?

It looks like you need to handle the BUSY signal before fetching the data.

From datasheet

Since one clock cycle of the serial clock is consumed with
BUSY going high (while the MSB decision is being made),
16 additional clocks must be given to clock out all 16 bits
of data; thus, one conversion takes a minimum of 25 clock
cycles to fully read the data. Since most microprocessors
communicate in 8-bit transfers, this means that an additional
transfer must be made to capture the LSB.

In code we add a delay to skip the busy bit.
If that does not work the program must explicitly wait for the pulse on the BUSY pin.

#include <SPI.h>

//based off GPIO??
// #define CS 1
// #define MOSI 9
// #define MISO 8
// #define SPICLOCK 7

#define SELECT_PIN      1   //  Chip select pin (any digital pin)
#define BUSY_PIN        2   //  todo



uint16_t read_adc(int channel)
{
  uint8_t commandbits = 0x97;  //  default, channel 0

  //  make command byte based on desired channel
  switch (channel)
  {
    case 0:
      commandbits = 0x97;  //  Start bit, Channel 0 + no shutdown between conversions.
      break;
    case 1:
      commandbits = 0xD7;
      break;
    case 2:
      commandbits = 0xA7;
      break;
    case 3:
      commandbits = 0xE7;
      break;
    default:
      commandbits = 0x97;  //  channel 0
      break;
  }

  //  Configure SPI settings: Speed(data sheet), MSBFIRST, SPI_MODE0
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

  digitalWrite(SELECT_PIN, LOW);           //  select ADS8341
  SPI.transfer(commandbits);               //  send the command byte and receive the first response simultaneously

  //  need delay due to BUSY bit
  delayMicroseconds(100);  //  to be tuned

  uint8_t highBits = SPI.transfer(0x00);  //  send dummy byte
  uint8_t lowBits  = SPI.transfer(0x00);  //  send dummy byte
  digitalWrite(SELECT_PIN, HIGH);         //  deselect ADC

  SPI.endTransaction();

  return highBits * 256 + lowBits;
}


void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(__FILE__);
  Serial.println();

  //  Set pin modes
  pinMode(SELECT_PIN, OUTPUT);
  //  unselect device at start
  digitalWrite(SELECT_PIN, HIGH);


  //  initialize SPI library
  SPI.begin();
}


void loop()
{
  for (int channel = 0; channel < 4; channel++)
  {
    uint16_t value = read_adc(channel);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(": ");
    Serial.println(value);
    Serial.println();
    delay(500);
  }

  delay(1000);
}

mmm, reading further in the datasheet

As there is an external clock It needs an extra transfer.
in code:

#include <SPI.h>

//based off GPIO??
// #define CS 1
// #define MOSI 9
// #define MISO 8
// #define SPICLOCK 7

#define SELECT_PIN      1   //  Chip select pin (any digital pin)
#define BUSY_PIN        2   //  todo

uint16_t read_adc(int channel)
{
  uint8_t commandbits = 0x97;  //  default, channel 0

  //  make command byte based on desired channel
  switch (channel)
  {
    case 0:
      commandbits = 0x97;  //  Start bit, Channel 0 + no shutdown between conversions.
      break;
    case 1:
      commandbits = 0xD7;
      break;
    case 2:
      commandbits = 0xA7;
      break;
    case 3:
      commandbits = 0xE7;
      break;
    default:
      commandbits = 0x97;  //  channel 0
      break;
  }

  //  Configure SPI settings: Speed(data sheet), MSBFIRST, SPI_MODE0
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

  digitalWrite(SELECT_PIN, LOW);           //  select ADS8341
  SPI.transfer(commandbits);               //  send the command byte and receive the first response simultaneously

  uint32_t bits = SPI.transfer(0x00);
  bits = bits * 256;
  bits = bits + SPI.transfer(0x00);
  bits = bits * 256;
  bits = bits + SPI.transfer(0x00);
  bits = bits >> 7;                  //  remove the zero padding.
  digitalWrite(SELECT_PIN, HIGH);

  SPI.endTransaction();

  return bits;
}


void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(__FILE__);
  Serial.println();

  //  Set pin modes
  pinMode(SELECT_PIN, OUTPUT);
  //  unselect device at start
  digitalWrite(SELECT_PIN, HIGH);


  //  initialize SPI library
  SPI.begin();
}


void loop()
{
  for (int channel = 0; channel < 4; channel++)
  {
    uint16_t value = read_adc(channel);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(": ");
    Serial.println(value);
    Serial.println();
    delay(500);
  }

  delay(1000);
}

What is Vref?
What is COM?
Is ground connected?
Do you have the required decoupling capacitors?

Vref is 3.3V the COM is grounded, ive checked all grounds are connected. the decoupling caps are also in place. ive checked the DCLK, DIN and DOUT on the with an oscilloscope and found that the DCLK and DIN is getting to the board but im not getting the expected DOUT signal im getting the DCLK and DIN sum'd onto eachother at a much lower voltage. i dont have an image of it, i do have the DCLK and DIN though


Yellow is DCLK, green is DIN

Don’t be offended but I have to ask:
Is DOUT connected to MISO
and
DIN connected to MOSI?

and GPIO1 is D0.

yes, DOUT <-> MISO and DIN <-> MOSI, and GPIO1 is D0

Looks like you checked everyhing that could be checked.
Do you have a voltage connected to any of the ADS8341 inputs for testing, like an adjustable pot?
I guess it is possible that the IC could be bad.

yes, i have a pot connected to channel 0 with a range from 3.3-0V, ive also started to think that it could be the IC, ive ordered a new IC to test if thats the case.

I just notied on you scope traces the the voltages are higher than 3.3V and they should not be. Is Vcc = 3.3V?