Go Down

Topic: Connecting and using an ADS1232 (Read 72 times) previous topic - next topic

markandre21062001

Oct 20, 2018, 05:35 pm Last Edit: Oct 23, 2018, 04:34 pm by markandre21062001
(I'm new to external ADC's and SPI in general, so please be patient)

I need an external ADC for a school project as the resolution of the internal ADC of the Arduino UNO/Nano/Mega is just too low. So I decided to buy one on Amazon which was already soldered (See attached picture). It arrived yesterday and I realized that I have no clue how to use it. After some googleing I found these posts:
http://forum.arduino.cc/index.php?topic=130277.0
http://forum.arduino.cc/index.php/topic,128823.0.html

I connected (based on the code I found) the following pins to my Arduino Uno:

Gain0/1  5V
REFP  5V
SPEED  5V
TEMP  GND
A0  GND
CLKIN  GND
DOUT  D12
CLK  D13
PDWN  D9


The code:

Code: [Select]
#include <SPI.h>


#define MISOPIN 12

#define SCLKPIN 13

#define PDWN 9

#define A0 5



//MUX Pin Settings

//    A0    |    A1    |    Inputs

// Low  (0) | Low  (0) | AINP1 11 AINN1 12

// Low  (0) | High (1) | AINP2 18 AINN2 17

// High (1) | Low  (0) | AINP3 13 AINN3 14

// High (1) | High (1) | AINP4 16 AINN4 15



uint32_t data[3];
long val = 0;

// declare 3 bytes = 24 bits


void setup()

{

 Serial.begin(9600);

 

 pinMode(SCLKPIN, OUTPUT); pinMode(MISOPIN, INPUT); pinMode(PDWN, OUTPUT);

 // corresponding to SCK pin and DRDY/DOUT pin on ADC


 digitalWrite(PDWN, HIGH);

 digitalWrite(A0,LOW);


 

 reset_adc();

 // put ADC on reset at the outset

 

SPI.begin();

SPI.setBitOrder(MSBFIRST);

SPI.setDataMode(SPI_MODE1);

 // initialize SPI (with default settings, including...

 // CPOL = 0: so that SCLK is normally LOW

 // CPHA = 0: data sampled on rising edge (LOW to HIGH)

 // perhaps try changing CPHA ??

 

 digitalWrite(SCLKPIN, LOW);

 // release ADC from reset; now we're at a known point

 // in the timing diagram, and just have to wait for

 // the beginning of a conversion cycle

}


void loop()

{

 if (digitalRead(MISOPIN) == LOW) read_adc();

 // "sort of" an interrupt to go to read_adc routine;

 // can use hardware interrupt in future but now just poll


 delay(100);

}


void reset_adc()

// to reset ADC, we need SCLK HIGH for min of 4 CONVCYCLES

// so here, hold SCLK HIGH for 5 CONVCYCLEs = 1440 usec

{

 digitalWrite(SCLKPIN, HIGH);

 delayMicroseconds(1440);

}


void read_adc()

{

 drdy_wait();

 // go to drdy_wait routine, where we wait for

 // DRDY phase to pass, and thus for DOUT phase to begin


 data[0] = SPI.transfer(0x00);

 data[1] = SPI.transfer(0x00);

 data[2] = SPI.transfer(0x00);

 // read in adc data (sending out don't care bytes)

 // and store read data into three bytes */

if (data[2] & 0x80)
    val = 0xff;
val = (val << 8) | data[2];
val = (val << 8) | data[1];
val = (val << 8) | data[0];

 Serial.println(val);

 // print out data;

 // will these instructions eat into time significantly?

 // possible improvement: store all data from multiple cycles

 // into array, and print out only later at end.

}


void drdy_wait()

// wait for DRDY to pass and to reach start-point of DOUT

{

 delayMicroseconds(30);

 // to be safe, 30 usec, instead of 27 usec, which is

 // the expected period of DRDY phase

}

(based on: https://e2e.ti.com/support/data-converters/f/73/t/560004?Help-with-setting-up-an-ADS1234-with-4-load-cells-to-an-Arduino-Uno-or-a-Raspberry-Pi-3)

As said in the Datasheet, I can connect the AINN1 pin to ground to measure an unipolar signal on AINP1.
I'm not quite sure what a differential Signal is, so this was the best I can do.

I thought, if I connect AINN1 and AINP1 to Grund (or AINN1 - Gnd & AINP - 5V), I should get a constant number as result.
But thats not the case. I get random numbers starting at around -825242
and ending at ~1713729126.

Somebody knows why?

Go Up