Problem connecting to TI ADS1212P via SPI

Hello everyone. I need an ADC with more resolution than the one built in to the ATMega. I have a Texas Instruments ADS1212P that I have connected to my Arduino and I’m trying to get the two to talk via SPI, but I’m running in to issues.

Here is my sketch:

#include <SPI.h>

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
const int dataReadyPin = 9; 
const int chipSelectPin = 10;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  SPI.setDataMode(SPI_MODE1);
  pinMode(dataReadyPin, INPUT);
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin,HIGH);
}

void loop() {
  if (digitalRead(dataReadyPin) == HIGH) {
    digitalWrite(chipSelectPin,LOW);
    byte b0 = SPI.transfer(B10000000);
    Serial.println(b0,BIN);
    digitalWrite(chipSelectPin,HIGH);
    delay(250);
  }
}

My serial output looks like this:
10000000
10000000
10000000
10000000

It appears that the byte I get back from the device is exactly the same as the byte I send to it. Any idea what I’m doing wrong?

The device manual is here:

Thanks,
Lance

If you have SDOUT connected to MISO (Master In/Slave Out) you will have to set the SDL bit of the command register to 1. The default is to use the same pin (SDIO) for Input and output.

I do have SDOUT connected to MISO. The pin definitions list reads as if using SDIO for both input and output is optional, but I see in the Command Register bit descriptions that it does both input and output by default. I have modified my code to try to blindly send the command to change that, but it doesn’t seem to be working for me. I’m still getting the same data back as I sent to the ADC.

#include <SPI.h>

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
const int dataReadyPin = 9; 
const int chipSelectPin = 10;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  SPI.setDataMode(SPI_MODE1);
  pinMode(dataReadyPin, INPUT);
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin,HIGH);
  
  while (digitalRead(dataReadyPin) == LOW) { //Wait until this goes high
    delay(1);
  }
  digitalWrite(chipSelectPin,LOW);
  Serial.println("Setting CMD:SDL");
  SPI.transfer(B00000100); //Write to Command Register Byte 3
  SPI.transfer(B01000010); //Set SDL to use SDOUT
  digitalWrite(chipSelectPin,HIGH);
  delay(250);
}

void loop() {
  if (digitalRead(dataReadyPin) == HIGH) {
    digitalWrite(chipSelectPin,LOW);
    byte b0 = SPI.transfer(B10000000);
    Serial.println(b0,BIN);
    digitalWrite(chipSelectPin,HIGH);
    delay(250);
  }
}

Hi

So just a question.. It should be pretty much simpler to just use an external crystal, like a 2 Mhz... instead of reducing the spi port speed ? Or have you already figure out ?

Yes, we ended up getting a 2MHz crystal to make it work.