0

I'm a newbie and I'm trying to read an ADS1232 with an Arduino for a Weight Scale Project.

I read data through the SPI interface, but i don't receive the result.

#include <SPI.h>

#define MISOPIN  50  //DATA
#define SCLKPIN  52  //SCLK
#define PDWN     53  // SS
#define SPEED       5 
#define GAIN0       7
#define GAIN1       6
#define CLKIN       10 
#define A0          9
#define TEMP        8


uint32_t byte1;
uint32_t byte2;
uint32_t byte3;
uint32_t finaladc = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);



  pinMode(PDWN, OUTPUT);  
  pinMode(MISOPIN, INPUT);
  pinMode(SCLKPIN, OUTPUT);
  pinMode(SPEED, OUTPUT);
  pinMode(GAIN0, OUTPUT);
  pinMode(GAIN1, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(TEMP, OUTPUT);

  digitalWrite(GAIN0, HIGH);
  digitalWrite(GAIN1, HIGH);
  digitalWrite(SCLKPIN, LOW);
  digitalWrite(A0, LOW);
  digitalWrite(TEMP, LOW);
  digitalWrite(SPEED, HIGH);//0-->  10SPS ,1-->80SPS
  digitalWrite(PDWN, HIGH);  //0-->  POWERDOWN(SLEEPING -NO CONVERSION) ,1-->WORKING MODE

  reset_adc();

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);

  digitalWrite(SCLKPIN,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(MISOPIN)== LOW) read_adc();

  delay(1000);

}

void reset_adc()  {
  digitalWrite(SCLKPIN,HIGH);
  delayMicroseconds(1400);

}

void read_adc()  {
  drdy_wait();
  uint8_t i;
  finaladc = SPI.transfer(0xff);  
  finaladc |= (uint32_t)SPI.transfer(0xff) << 8;
  finaladc |= (uint32_t)SPI.transfer(0xff) << 16;
  Serial.print ("ADC_value:  "); 
  Serial.println(finaladc,DEC);
  Serial.println();

}

void drdy_wait()
{
  delayMicroseconds(30);
}

Has anyone worked with this? Can you help me? Thank you

  • Welcome to stackexchange. Would you show your code please? It is hard to recognise problems without it. – smajli Mar 14 '19 at 7:57
  • This is here Google – Thanh Van Mar 14 '19 at 9:55
  • the ADS1232 doesn't have SPI – Juraj Mar 14 '19 at 10:56
  • I've used SPI with the ADS1232. You've a lot of problems, but the first one is your reset_adc() is all wrong, among other things reset is via pulling the PWDN pin low for more than 10 uS. Start there. – RamblinRose Mar 14 '19 at 13:50
1

I fished out some code I wrote a while back while evaluating the 1232. SPI is a headache because of the need toggle the clock signal to prevent the last data bit from 'sticking', which will botch repeated reads when the last data bit is high.

If you are absolutely required to use SPI stop reading this answer.

Everything you need to know is on pages 18 and 19 of the ADS1232 datasheet. Note this is strictly demo material, for example it doesn't take into account settle time when switching channels.

int32_t read_adc(const uint16_t wait_millis) {    
   int32_t data = 0;     
   // reset ADC
   digitalWrite(ADS1232_PDWN, LOW);
   delayMicroseconds(10);
   digitalWrite(ADS1232_PDWN, HIGH);
   delayMicroseconds(10);

   for (; data < wait_millis && digitalRead(ADS1232_DRDY_DOUT) != LOW; 
        delay(1), 
        data++);

    if (data == wait_millis) {
        // timeout      
        return -1;
    }

   // read in 24 bits, see Page 19 of the datasheet

   data = 0;    
   for (uint8_t i = 0; i < 24; i++) {
        digitalWrite(ADS1232_CLK, HIGH); // clock out next data bit
        data <<= 1;
        data |= digitalRead(ADS1232_DRDY_DOUT);
        digitalWrite(ADS1232_CLK, LOW);
    }
    // adjust for sign. See page 18 of datasheet
    if (data & 0x00800000)
        data |= 0xFF000000;    
    // avoid having DRDY/DOUT remain in the state of the last bit
    // see page 19 of datasheet 
    digitalWrite(ADS1232_CLK, HIGH);
    delayMicroseconds(10);
    digitalWrite(ADS1232_CLK, LOW);

    return data;
}
| improve this answer | |
  • Thank you!! Ramblin Rose!! I will try and respond to you – Thanh Van Mar 15 '19 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.