This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1231: no

Part Number: ADS1231
Other Parts Discussed in Thread: ADS122C04,

Hello

I m Uday ,

I used adds1231 for data coversion purpose my question is 

1) if ADS1231 is not support I2C communication and support 2 -Wire  Serial Digital Interface, So From Which Two Pin,I have to communicate with my Controller?

2) Can  I connect that two pin to SPI Line Of my Controller ?

3) If Yes For SPI Connection , ADS1231 which line use as Chip Select?

Please ASAP give me solution for my quries.

Thank You.

  • Hi Uday,

    Welcome to the E2E forum! The ADS1231 is an SPI compatible communication device using Mode 1. The ADS1231 does not communicate through I2C (see the ADS122C04 for a 24-bit I2C ADC).

    To connect to your microcontroller connect the SCLK to the micro SCLK, and DRDY/DOUT pin of the ADS1231 to the micro MISO pin. The MOSI and CS lines on the micro are to be left disconnected as the ADS1231 has no input pin to receive data nor does it use CS (as it is always in CS mode).

    To initiate your SCLKs you would need to write a dummy byte to the SPI TX buffer even though there is nothing connected to the MOSI line. This is how the micro will initiate the SCLKs. Once all the clocks have been sent, read the RX buffer data. You will need to do this three times if your micro sends clocks in byte increments.

    Another more code intensive method is to use 2 GPIO and bit-bang the port by using one GPIO as an output to toggle the SCLK line. The data are read on the second GPIO pin used as an input that is connected to DRDY/DOUT. The pin should be read after the falling edge of the SCLK but before the next rising edge of SCLK.

    Best regards,
    Bob B
  • Hi BOB,

       I'm trying to use bit-bang method but i'm not able to read the data, I connected the pins as per the datasheet circuit diagram but always i'm getting value as zero (Attached Arduino Code).

    #define DATA 2
    #define CLOCK 3
    
    uint32_t data=0;
    
    void setup() {
      // put your setup code here, to run once:
    pinMode(DATA,INPUT);
    pinMode(CLOCK,OUTPUT);
    digitalWrite(CLOCK,LOW);
    Serial.begin(115200);
    Serial.print("WeightSensor\n");
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      Serial.println("Waiting for the ADS1231");
      while(digitalRead(DATA)==HIGH);  // Waiting for the IC to be ready
      Serial.println("Reading Data...");
      for(char i=24; i>=0; i++)        // Loading data into buffer
      {
        digitalWrite(CLOCK,HIGH);
        digitalWrite(CLOCK,LOW);
    
        if(digitalRead(DATA)==HIGH)
        data|=(1 << i);
        else
        data&=~(1 << i);
      }
      Serial.println(data);
      delay(1000);
    }

    Thanks & Regards,

    Vijay Rakesh

  • Hi Vijay,

    How do you have the rest of the pins of the ADS1231 connected?  AVDD and DVDD must both be powered and the reference voltage also applied.  Digital pins PDWN and SPEED must be connected.  PDWN pin should be high or the device will be in a powered down state.

    As to your code there a couple of issues.  I would suggest monitoring the communication with an oscilloscope or logic analyzer to verify the communication.  In the 'for' loop you are starting at bit 24 and it appears that the loop will continue without stopping.  So you should be decrementing instead of incrementing 'i'.  

    You should also start at 23 so that you don't shift the value too far and beyond 24 bits.  You should also reset the data value each time that it is read just to make sure there are no errors in the reading of data.  If you do not clear it you will end up with 8 bits of the previous data the next cycle.

    I would also suggest adding a 25th clock after the data results are read to force DRDY/DOUT to a high state, otherwise the DRDY/DOUT will be at the last state of the last bit of the conversion result which could be either high or low.  See section DATA RETRIEVAL on page 13 of the ADS1231 datasheet.

    You may also need to add a delay between setting the CLOCK high and then setting the CLOCK low.  Depending on the speed of the processor the transition may be too fast.  The SCLK high time must be at least 100ns.  This is shown in Figure 19 also on page 13 of the ADS1231 datasheet.

    Your code may look something like this (I don't have a way of verifying it but it should be close.)

    void loop() {
      // put your main code here, to run repeatedly:
      Serial.println("Waiting for the ADS1231");
      while(digitalRead(DATA)==HIGH);  // Waiting for the IC to be ready
      Serial.println("Reading Data...");
      data = 0;
      for(char i=23; i>=0; i--)        // Loading data into buffer
      {
        digitalWrite(CLOCK,HIGH);
        //may need some delay here must be at least 100ns between CLOCK high and CLOCK low
        digitalWrite(CLOCK,LOW);
    
        if(digitalRead(DATA)==HIGH)
        data|=(1 << i);
        else
        data&=~(1 << i);
      }
        // add 25th clock to force DRDY/DOUT high
        digitalWrite(CLOCK,HIGH);
        //may need some delay here must be at least 100ns between CLOCK high and CLOCK low
        digitalWrite(CLOCK,LOW);
        // data is a 32 bit value but the ADS1231 is binary 2's complement 24-bit data so negative values will need to be properly sign-extended
        // and additional code will need to be added if you have negative results.
      Serial.println(data);
      delay(1000);
    }

    Note that I mentioned sign-extension in the code snippet.  You defined the 'data' variable as an unsigned 32-bit integer, but the ADS1231 outputs data as binary 2's complement using the msb as the sign bit.  To take advantage of this you will need to change the variable to a signed integer and then properly sign-extend the 24-bit value to a signed 32-bit value.  So if bit 23 is high (bits are from 0 to 23 for a total of 24) then you should add or 'OR' the value 0xFF000000 to your 'data' variable.  This is how you would extend the sign bit to the full 32 bit word.

    Best regards,

    Bob B

  • Hi Bob,

    Thanks for your valuable suggestion and I have one more last question, How to calculate scale? I need an accuracy of minimum 0.1gram.

    Warm Regards,
    Vijay Rakesh
  • Hi Vijay,

    The ADS1231 converts an analog input voltage to a code.  The resolution will be related to the noise of the ADC and any system noise.  If we assume the system noise is equal to or less than the noise of conversion (which is the best possible case and most likely the noise will be worse) you can determine the outcome, but you will have to do some conversion.

    Accuracy will relate to calibration.  I think what you are really asking for is a level of precision, or repeatability, of 0.1g.  The formula for repeatability is load cell maximum weight divided by the maximum output voltage of the load cell (or the sensitivity of the load cell in mV/V times the excitation voltage) times the peak-to-peak noise of the ADC at the data rate being used. 

    As an example, let's say we are using a load cell capable of weighing 10kg that has a sensitivity of 2mV/V and an excitation of 5V.  If the ADS1231 is set to use 10sps, the noise from Table 1 of the ADS1231 datasheet is 231.9nV peak-to-peak.  To calculate the best case repeatability we find:

    Repeatability = 10kg / (2mV/V * 5V) * 231.9nV = 10kg / 10mV *231.9nV  = 0.232g 

    So in this use case you cannot achieve the desired 0.1g repeatable resolution without lowing the noise.  One method of lowering the noise is by averaging.  So depending on the noise and the maximum load cell weight that can be applied you will see different repeatability results.

    The actual calculation of the weight as it relates to the ADC output code needs to take into account the total span of the load cell.  As there may be offset of the load cell and potential gain error you should calibrate the system.  There may also be a weight that shouldn't be a part of the end result such as a platter or platform the measured weight is to be placed upon.  This is a process called TARE.  I would suggest looking at the ADS1231REF user's guide (SBAU175A) in section 2.1.1 on page 8 which shows how the weight is determined.

    Best regards,

    Bob B 

  • Hi Bob B,

    Thank you so much.