Can't sample ADC1022 with SPI1 but SPI works fine

I'm getting about 190 kSps with the ADC1022S021 on SPI using the RobTillaart ADC08XS library but using this SPI1 code only get zeros. I tried every suggestion I found on line and other SPI1 wirings. Got good results on other wirings with SPI. Just Pico RP2040 on Philhower core with Win11 Arduino. Does ADC08XS talk to SPI1 ?

//
//   Credits to
//  AUTHOR: Rob Tillaart
//  URL: https://github.com/RobTillaart/ADC08XS

#include "ADC08XS.h"
#include <spi.h>

ADC122S adc;          
#define bufSize  256
uint16_t buf[bufSize] = {0};

void setup(){

  Serial.begin(115200);
  delay(3000);

  SPI1.setRX(12);  // MISO orange    16      4
  SPI1.setTX(11);  // MOSI   red     19      3
  SPI1.setSCK(14);   //   yellow     18      2
  SPI1.setCS(13);   //     white     17      5

  SPI1.begin();

  adc.begin(13); //  

 for (int i = 0; i<bufSize; i++){
    buf[i] = adc.read(0);
 }

  for (int i = 0; i<bufSize; i++){
    Serial.print(i);
    Serial.print("  ");
    Serial.println(buf[i]);
    delay(10);
 }

}

void loop(){
}

Look at the library code...

If you use custom SPI other than default, you must pass the reference to your SPI instance to ADC constructor:

It would be helpful to know which Arduino board you're using.

1 Like

from the first post:

Thanks.

Fixed!!!
ADC122S adc(&SPI1); Worked
Wow that was fast.
Thank You

1 Like

@larry_gorham

It is a recent / new library, I have to add an SPI1 example.
Issue created - Add example for usage with SPI1 · Issue #6 · RobTillaart/ADC08XS · GitHub

This corrected code now works fine on core 1 with the SPI running faster. It samples at 174 kSps. Which is a bit slower than running on core 0 (190 kSps) but acceptable for now. I'll try the faster single channel ADC chip next. Many thanks to all.

//
//   Credits to
//  AUTHOR: Rob Tillaart
//  URL: https://github.com/RobTillaart/ADC08XS

#include "ADC08XS.h"
#include <spi.h>

ADC122S adc(&SPI1);

#define bufSize  256
uint16_t buf[bufSize] = {0};
uint32_t SPIspeed = 24000000UL;

void setup(){
}

void loop(){
}

void setup1(){

  Serial.begin(115200);
  delay(3000);

  adc.setSPIspeed(SPIspeed);

  SPI1.setRX(12);  // MISO orange    16      4
  SPI1.setTX(11);  // MOSI   red     19      3
  SPI1.setSCK(14);   //   yellow     18      2
  SPI1.setCS(13);   //     white     17      5

  SPI1.begin();

  adc.begin(13); //  

 for (int i = 0; i<bufSize; i++){
    buf[i] = adc.read(0);
 }

  for (int i = 0; i<bufSize; i++){
    Serial.print(i);
    Serial.print("  ");
    Serial.println(buf[i]);
    delay(10);
 }

}

void loop1(){
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.