Read ADS 7844 Data using SPI protocol

Hello guys.

I've been working on reading the output data from this ADC: http://www.ti.com/lit/ds/symlink/ads7844.pdf

It's a 12-Bit, 8-Channel Serial Output Sampling ADC.

From the datahseet, I see it uses SPI protocol, but I'm not being able to get data back from the device. Is the SCLK compatible with the readings sample?

Anybody can help with some code to read channels CH0~CH7 in Single Ended mode and no Power Down between conversions ? (pg 11 on datasheet explains the values to be sent) I need to display the data in the Serial monitor as well...

Thanks a lot!

I would try something like this.

#include <SPI.h>

// set to the slave select pin for the adc
#define adSS 8

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

  pinMode(adSS, OUTPUT);
  digitalWrite(adSS, HIGH);

  SPI.begin();
}

void loop() {
  byte commandByte;
  byte result[2];
  
  for(byte x=0;x<8;x++) {
    // set to adc# and bit3 HIGH
    commandByte = x + 8;
    // shift into position
    commandByte = commandByte << 4;
    // set low 4 bits HIGH
    commandByte = commandByte | 0x0f;   

    // enable ADC SPI slave select
    digitalWrite(adSS, LOW);
    delayMicroseconds(1);

    SPI.transfer(commandByte);
    // you might need to increase this delay for conversion
    delayMicroseconds(2);

    // get results
    result[0] = SPI.transfer(0);
    result[1] = SPI.transfer(0);

    // disable ADC SPI slave select
    digitalWrite(adSS,HIGH);    

    Serial.print("AD");
    Serial.print(x);
    Serial.print(" = ");
    Serial.print(result[0]);
    Serial.print(" ");
    Serial.println(result[1]);
    delay(100);
  }

  Serial.println();
  delay(1000);
}

Thanks SurferTim, I'll be home soon. I'll let you know the results!

If it doesn't work first time, there could be a bus speed challenge. It appears that 5MHz is about as fast as this device will work, and the SPI bus is default at 4MHz. You might need to slow it down a bit. This will set the SPI bus to 2MHz.

SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);

Apparently it's working! Here is a picture of the Serial Monitor.

Although I don't really understand what I'm reading.

For example: I have an accelerometer in CH4. When the sensor is laying on my desk, I get 1.56 V out of it. That voltage goes to the ADC that is working with a 3.25 Vref. That means that for 0V it has to send back 0 and for 3.25V (in the channels input) 4096, correct ? Well, for 1.56V I should get something around 1825 from the ADC.

What exactly is being displayed in the Serial monitor ? I don't see any relations between the values.

Thanks again for the reply!

It appears it is reading the ADs ok. Now you need to translate that from 2 bytes to one integer. The timing schematic is a bit vague on the timing of the data. It is a 12 bit AD, so result[0] should have the upper 7 bits, and result [1] should have the lower 5 bits.

I would combine them into an integer and shift the whole thing right 3 bits. Something like this?

int resultInt = result[0];
resultInt = resultInt << 8;
resultInt = resultInt | result[1];
resultInt = resultInt >> 3;
Serial.println(resultInt);

Awesome Job!

I would expect around 1825 in CH4.

I guess it's working just fine!

Now if I want to manipulate specific readings (like, just for CH5), can I do something like:

if(x==4){
int AccelY=resultInt;
}

Thanks a lot!

Yep! :)

SruferTim, thanks a lot for your help! I really appreciated it!

I'm new in the forum, so is there any kind of rating for the comments ? I would gladly give them 5 star.

It appears someone just bumped my karma. That is good reward for me.

I suppose that it was me! LOL.

Good to know it helps.

Thanks again! :)